0
votes

Have a situation where the event to remove an item from a Collection originates from the View of the item itself.

I can think of a "hacky" way using an event hub to send the message to be removed from child to parent. But is there a more elegant way to do this such as a well established pattern or mechanism in Backbone (or Marionette) itself that I'm not familiar with?

Example:

A collection of views where the user would click the 'x' for the row to be removed. The 'x' button would reside in the View of the item itself:

Britney Spears   x
Miley   Cyrus    x
Paris   Hilton   x
1
Could you elaborate what you mean by "hacky" event hub ?Jonas Geiregat
only remove from collections or also delete it from the server?VuesomeDev

1 Answers

1
votes

In the view, listen for the click to close it. From there you can destroy the model (http://backbonejs.org/#Model-destroy), which will fire an event that will bubble up into all of the collections that it is contained it. This will tell each collection to remove that model allowing it to then be cleaned up by the GC