Reputation: 11406
I have a collection set on my view. I'd like to render any time the collection is changed. However, it appears that according to the Backbone API docs 'change' isn't a valid event for a collection. So I've currently got this.collection.on('add reset remove');
which isn't really ideal.
What's the recommended way to handle this? Is there a standard way to track all changes to a collection in Backbone?
Upvotes: 0
Views: 99
Reputation: 44589
Collection don't have change
events on their own. Although, they bubble the change events of their models.
So you can do:
this.collection.on("change");
// Or better
this.listenTo(collection, "change");
Relevant documentation: http://backbonejs.org/#Collection
Upvotes: 1
Reputation: 9705
Yes, you can use the all
event. But why is what you have not ideal?
Also, the change
event will bubble up to the collection, so you can use that as well. Although typically you wouldn't update a collection view, but individual subviews representing each item.
Upvotes: 2