What is a good method for sending a message from a Child view to its parent Collection view in Backbone.js or Marionettejs?
Normally I send the message through the collection:
ChildView = Backbone.Marionette.ItemView.extend({
send_message: function(){
this.model.collection.trigger('some-message');
}
})
ParentCollectionView = Backbone.Marionette.CollectionView.extend({
// ON RENDER
onRender: function(){
this.listenTo(this.collection, 'some-message', this.do_something);
}
// DO SOMETHING
do_something: function(){
alert('did something');
}
});
I think this is not right because:
- I'm sending the message from the child view, through the data, back to the parent view
- In this instance, the message does not relate to the data, its strictly message passing between views about view stuff
- The model could belong to more than one collection
Instead, I would like to send a message directly from a child view to its parent collection view. (actually, I'm using a composite view, not sure if that matters, wanted to keep the example simple though).