After calling collection.fetch({ add: true }) on a Backbone collection, I’d like to trigger an event once the view of the updated collection has finished rendering.
The “collection view” has an “add” method, which generates an “item view” for each new item in the collection, calls “render” on that view, and adds it to the collection view.
Is there a way to trigger an event when fetching a collection has finished, and all items have been added and rendered?
The
fetchmethod on collections takes asuccessparameter:The
successcallback will be called after the collection has been updated so it will be called after all the"add"events have been triggered and dealt with. So you could do this:and anyone that cares could
collection.on('fetched_and_notified', ...)to listen for such an event. If you wanted, you could provide your ownfetchimplementation to trigger this event automatically, something like this: