Is it possible to override the collection.add method globally in backbone like so:
Backbone.Collection.prototype._add = Backbone.Collection.prototype.add;
Backbone.Collection.prototype.add = function(models, options) {
var = newModels = models.items;
Backbone.Collection.prototype._add(newModels, options);
}
The api I'm using ALWAYS contains the actual models one level down for collections. Under items
and I find myself overriding the .add
method for all collections. I tried what I have above but it didn't seem to work. Any ideas?
Thanks,
Luis
Try the following:
var Example = Backbone.Collection.extend({
add: function(models, options) {
Backbone.Collection.prototype.add.call(this, models.items, options);
}
})
Then you can extend all collections from Example
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With