Search code examples
javascriptmarionette

Accessing Marionette's ItemView elements inside CompositeView


This question relates to Marionette.js

Lets say I have an ItemView: ItemView1 which renders a template with a
<div id="div1itemview">

In a CompositeView: CompositeView1, I have a template which has a
<div id="div1CompositeView">
CompositeView1 also has itemView: ItemView1

I am defining CompositeView1 and ItemView1 in such a way that the final html will be:

<div id="div1CompositeView">

    Outer div for doing things

    <div id="div1ItemView">

        Inner div for doing things

    </div>

</div>

My question is: Can we access "click #div1ItemView" event inside CompositeView1?

Put in another way - Do we have access to (child) ItemView elements inside the (parent) CompositeView?

(Does the same hold true for a CollectionView and its ChildView?)

Thanks!


Solution

  • Elements of ItemView can be accessed by the parent CompositeView simply by using their (elements of ItemView's) id in the CompositeView.

    Corollary: Events pertaining to ItemView elements can be triggered inside the parent CompositeView!