Reputation: 1984
Remove event on backbone collection is triggered when the model has been removed from the collection.
But I need to differentiate whether destroying the model triggers the remove event on collection or just removing the model from collection triggers the remove event on collection.
Upvotes: 1
Views: 355
Reputation: 35730
There's no easy way to differentiate those two cases. My recommendation would be to override the remove
method yourself and have it trigger your own event(s):
var YourCollection = Backbone.Collection.extend({
remove: {
this.trigger('aboutToRemovedViaRemoveMethod');
// Call the original remove
var removeResult = Backbone.Collection.prototype.remove.apply(this, arguments);
this.trigger('removedViaRemoveMethod');
return removeResult;
}
});
And then of course destroy
you can already listen for separately, as it has its own event.
Upvotes: 1