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
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
Share asked Jul 18, 2012 at 18:23 luisgoluisgo 2,4754 gold badges25 silver badges30 bronze badges 2-
Note:
var = newModels = models.items;
should bevar newModels = models.items;
. I'm aware of it but that is not what is breaking the code. – luisgo Commented Jul 18, 2012 at 18:27 - Ever get this resolved? – seebiscuit Commented May 12, 2014 at 15:36
1 Answer
Reset to default 8Try 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
.