[#258,model][xs]: tiny bugfix for cases where fields in raw state contain a non-string - fixes #258.
This commit is contained in:
@@ -105,11 +105,12 @@ my.Dataset = Backbone.Model.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fields is an array of strings (i.e. list of field headings/ids)
|
// fields is an array of strings (i.e. list of field headings/ids)
|
||||||
if (fields && fields.length > 0 && typeof fields[0] === 'string') {
|
if (fields && fields.length > 0 && typeof(fields[0]) != 'object') {
|
||||||
// Rename duplicate fieldIds as each field name needs to be
|
// Rename duplicate fieldIds as each field name needs to be
|
||||||
// unique.
|
// unique.
|
||||||
var seen = {};
|
var seen = {};
|
||||||
fields = _.map(fields, function(field, index) {
|
fields = _.map(fields, function(field, index) {
|
||||||
|
field = field.toString();
|
||||||
// cannot use trim as not supported by IE7
|
// cannot use trim as not supported by IE7
|
||||||
var fieldId = field.replace(/^\s+|\s+$/g, '');
|
var fieldId = field.replace(/^\s+|\s+$/g, '');
|
||||||
if (fieldId === '') {
|
if (fieldId === '') {
|
||||||
|
|||||||
@@ -180,6 +180,21 @@ test('_normalizeRecordsAndFields', function () {
|
|||||||
records: null
|
records: null
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
in_: {
|
||||||
|
fields: [ 1, 1, 3 ],
|
||||||
|
records: null
|
||||||
|
},
|
||||||
|
exp: {
|
||||||
|
fields: [
|
||||||
|
{id: '1'},
|
||||||
|
{id: '11'},
|
||||||
|
{id: '3'}
|
||||||
|
],
|
||||||
|
records: null
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// field is *not* a string
|
||||||
// records array but no fields
|
// records array but no fields
|
||||||
{
|
{
|
||||||
in_: {
|
in_: {
|
||||||
@@ -267,6 +282,7 @@ test('_normalizeRecordsAndFields', function () {
|
|||||||
out = dataset._normalizeRecordsAndFields(item.in_.records, item.in_.fields);
|
out = dataset._normalizeRecordsAndFields(item.in_.records, item.in_.fields);
|
||||||
deepEqual(out, item.exp);
|
deepEqual(out, item.exp);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user