mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Merge pull request #3875 from Flamefork/3871-set-parse-undefined
Fixed Collection#set regression when parse returns falsy value
This commit is contained in:
@@ -824,7 +824,7 @@
|
||||
if (options.parse && !this._isModel(models)) models = this.parse(models, options);
|
||||
|
||||
var singular = !_.isArray(models);
|
||||
models = singular ? [models] : models.slice();
|
||||
models = singular ? (models ? [models] : []) : models.slice();
|
||||
|
||||
var at = options.at;
|
||||
if (at != null) at = +at;
|
||||
|
||||
@@ -1817,4 +1817,12 @@
|
||||
model.trigger('change');
|
||||
});
|
||||
|
||||
QUnit.test('#3871 - falsy parse result creates empty collection', function(assert) {
|
||||
var collection = new (Backbone.Collection.extend({
|
||||
parse: function (data, options) {}
|
||||
}));
|
||||
collection.set('', { parse: true });
|
||||
assert.equal(collection.length, 0);
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user