[#258,model][xs]: tiny bugfix for cases where fields in raw state contain a non-string - fixes #258.
This commit is contained in:
parent
dd8641ded2
commit
f6a3395b40
@ -105,11 +105,12 @@ my.Dataset = Backbone.Model.extend({
|
||||
}
|
||||
|
||||
// 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
|
||||
// unique.
|
||||
var seen = {};
|
||||
fields = _.map(fields, function(field, index) {
|
||||
field = field.toString();
|
||||
// cannot use trim as not supported by IE7
|
||||
var fieldId = field.replace(/^\s+|\s+$/g, '');
|
||||
if (fieldId === '') {
|
||||
|
||||
@ -180,6 +180,21 @@ test('_normalizeRecordsAndFields', function () {
|
||||
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
|
||||
{
|
||||
in_: {
|
||||
@ -267,6 +282,7 @@ test('_normalizeRecordsAndFields', function () {
|
||||
out = dataset._normalizeRecordsAndFields(item.in_.records, item.in_.fields);
|
||||
deepEqual(out, item.exp);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user