Merge pull request #1021 from ahamid/reset_passes_options

small patch to allow passing options through reset to model initializer
This commit is contained in:
Jeremy Ashkenas
2012-03-19 14:00:58 -07:00
2 changed files with 15 additions and 1 deletions

View File

@@ -700,7 +700,7 @@
this._removeReference(this.models[i]);
}
this._reset();
this.add(models, {silent: true, parse: options.parse});
this.add(models, _.extend({silent: true}, options));
if (!options.silent) this.trigger('reset', this, options);
return this;
},

View File

@@ -440,6 +440,20 @@ $(document).ready(function() {
ok(_.isEqual(col.last().attributes, d.attributes));
});
test("Collection: reset passes caller options", function() {
var Model = Backbone.Model.extend({
initialize: function(attrs, options) {
this.model_parameter = options.model_parameter;
}
});
var col = new (Backbone.Collection.extend({ model: Model }))();
col.reset([{ astring: "green", anumber: 1 }, { astring: "blue", anumber: 2 }], { model_parameter: 'model parameter' });
equal(col.length, 2);
col.each(function(model) {
equal(model.model_parameter, 'model parameter');
});
});
test("Collection: trigger custom events on models", function() {
var fired = null;
a.bind("custom", function() { fired = true; });