Do ItemView triggers bubble up?
Asked Answered
M

1

8

I have a CompositeView for a table. I have triggers set in the child ItemView for each row...

var TableRow = Marionette.ItemView.extend({
    tagName: "tr",
    template: _.template($(TableTemplates).filter('#tableRow').html()),
    triggers: {
        "click td": "click:td"
    }
});

Are the triggers supposed to bubble up to the parent CompositeView?

From the docs...

Having access to these [the view, model, and collection properties of the view that triggered the event] allows more flexibility in handling events from multiple views. For example, a tab control or expand/collapse widget such as a panel bar could trigger the same event from many different views and be handled with a single function.

Wouldn't the "single function" be within the parent CompositeView so that it can react to the triggers from any of its child ItemViews? How does the CompositeView listen for the ItemView trigger?

Thanks

Maryjanemaryjo answered 24/5, 2013 at 17:46 Comment(0)
T
14

Yes, they bubble up.

The only thing to have in mind is that when an ItemView is called from a CompositeView or CollectionView, that trigger will have itemview prepended in the name, so:

click:td would be listen in the CompositeView as itemview:click:td

That string can be changed like this:

var CV = Marionette.CollectionView.extend({
  itemViewEventPrefix: "some:prefix"
});

So your trigger would be some:prefix:click:td

EDIT: On newer versions (not sure about the starting version), the prefix itemview has been changed to childview

More info here:

Marionette docs

Tunable answered 24/5, 2013 at 23:3 Comment(5)
What if you wanted to have the CompositeView make all of its children (ItemViews) listen to one of its events? (So the opposite of having the parent listen to the children)Oddson
can you please show in your answer how can I listen to that event ?Queasy
@SandipArmalPatil I couldn't get this working from the events or itemEvents hashes, so in the end I just put the following in my initialize function: this.listenTo(this, "itemview:whatever", fn);Patrol
Sorry, I am confused for this problem. I know the original question is bubbled up. But do you know how to bubble down? I mean trigger some function from parent view, compositeview or collectionview, to itemview.Punk
Sorry no idea, my backbone / marionette is completely off my mind.Tunable

© 2022 - 2024 — McMap. All rights reserved.