I've a collectionview
ItineraryEditorView
that is swapped in and out of a layout region.
The same instance of collectionView
is swapped in using region.show
instead of creating new instance for collectioView
every time. The render method on the collection calls delegateEvents()
method.
ItineraryEditorView = Marionette.CollectionView.extend({
tagName: "div",
emptyView: EmptyItineraryDayView,
itemView: ItineraryDayView,
initialize: function (options) {
},
render: function() {
Marionette.CollectionView.prototype.render.apply(this);
this.delegateEvents();
},
});
The view is swapped out by closing region:
plannerLayout.itineraryEditorRegion.close();
Swapping in the view:
itineraryEditorView.delegateEvents();
plannerLayout.itineraryEditorRegion.show(itineraryEditorView);
Deletion of a model is done by listening to the bubbled up event from itemView
to collectionView
(works, no issues here)
itineraryEditorView.on("itemview:delete:day", function(childView, model) {
days.remove(model); //days coll is passed in to coll view on instance creation
holiday.save();
});
I'd expect that this would be enough to ensure the the child itemViews
in the collection view are removed/closed when a model is removed from the underlying days collection. I can see that the collection is actually modified and and saved on the server,however the collection view is not altered.
This scenario of course works when before the collection view is swapped out first time.
The coll. view does update itself after I re-visit another tab and come back to this tab (thus the entire collection is rendered- confirming the change/deletion)
What is the best way get around this issue? If I recreate the instance of collection view, it does cause to lose other "on" handles in the code.