Are these two steps mandatory to delete a Model?
var model = collection.get(id);
model.destroy();
collection.remove(model);
Isn't there a way to destroy a model when it is removed from its collection?
Are these two steps mandatory to delete a Model?
var model = collection.get(id);
model.destroy();
collection.remove(model);
Isn't there a way to destroy a model when it is removed from its collection?
Model.bind("remove", function() {
this.destroy();
});
...
var model = new Model();
...
collection.remove(model);
Removing a model from a collection triggers the "remove"
event.
So if you want to, you can get models to bind to them and destroy themselves.
.create
we could have a .destroy
that destroys and removes a model on a collection
Calling collection.reset() without passing any models as arguments will empty the entire collection.
.destroy()
on your model, Backbone removes it from the server and (provided that succeeded) then removes it from its collection automatically.