Using MarionetteJS v1.0.3.
I have an instance of Marionette.Layout , which has two areas.
The first area is the CompositeView on the left, and the other area is the ItemView on the right.
CompositeView displays several ItemViews.
The idea is that the user clicks on one of the items in the collection on the left to fully display the selected entry in the ItemView on the right.
How the layout at the top subscribes to events in the chain: Layout> Region> Composite element> Item element
Since the layout at the top is the only one who knows about the detailed area on the right, this event needs to be consumed here completely from the CompositeView, where the click event will occur. I know that there are global events, but they are global, and there may be several layouts at the same time, so their events will collide.
LeftListPanelView = Marionette.CompositeView.extend({ template: "#leftPanel", itemViewContainer: "ul", events: { "click li": "rowClicked" }, rowClicked: function (e) { var itemid = $(e.currentTarget).data("itemid") * 1; var selectedItem = this.collection.get(itemid); if (selectedItem) { this.trigger("itemSelected", selectedItem); } } });
source share