Need to call .delegateEvents()
on all child views inside a parent "collection" view in order to re-delegate events after having removed the parent view from the page and then put it back on.
I can see two ways of doing this, both of which don't sound quite right to me in terms of proper practices:
- Whenever
addOne(
) is called in the parent view, save the child view that was just created to a list. When the events need to be re-delegated later on when the view is added back onto the page. Use the array to scroll back through that list and call.delegateEvents()
on each child view item. The problem with this approach, is the creating of a separate array to hold everything inside the view when the view already has a Backbone-sanctioned way to influence it's child views throughthis.collection.each()
- Use the built in
View.collection.each()
inside the view to scroll through each child model. Trigger an event on each model that causes its corresponding view to call.delegateEvents()
on itself. The problem with this approach is that a purely view-oriented action is being routed through the models.
Are either of these approaches any good or is there a better way that I should be doing this?
Thanks so much!