Question

I have the next scenario using Marionette:

  • Three different regions
  • Showing a CompositeView in a region
  • The Composite View's collection have three different events added automatically: add, remove and reset
  • Changing the view rendered in the region
  • The Composite View's collection does not have anymore the events: add, remove and reset

Why?

Était-ce utile?

La solution

When you create a CollectionView (or any other Marionette view) the view calls .listenTo() for each of the events (add, remove, reset) on the collection. So events aren't necessarily on the collection itself but tracked by the view.

When you show another view in the region the previous view's .close() method is called which also calls the previous view's .stopListening() method which removes the listeners for your add, remove, and reset events.

Generally speaking, Marionette expects you to create a new view each time you show it in a region since when a region closes it's current view, the view loses all it's event listeners...

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top