Delete a backbone model without sending DELETE
Remove a model from a collection, but do not send DELETE HTTP request
Wrong (this will trigger HTTP DELETE request) :
var model = this.collection.at(4);
model.destroy();
Good :
model.trigger("destroy", model);
When do you need this ?
In my case it was when a model was deleted on server-side from another controlling interface, and the interface was fetching this model periodically to display some sort of live statistics. The fetch was failing due to the object being deleted and I triggered the model destroy in the fetch error handler. Usually most people don't run into this situation because usually we update (reset) the whole collection altogether. Like this we have the new ones added as well as not having the ones removed.
Recent Comments