0

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!

Vijay Singh
  • 277
  • 1
  • 3
  • 15

2 Answers2

1

A more robust approach would be to have the CompositeView listen for an event dispatched from the ItemView using triggers:

var MyItemView = Backbone.Marionette.ItemView.extend({
    triggers: {
        'click': 'do:something'
    }
});

var compositeView = Backbone.Marionette.CompositeView.extend({
    childView: MyItemView,
    onChildviewDoSomething: function () {
        console.log('do something');
    }
});

childEvents are another, similar option.

pdoherty926
  • 9,895
  • 4
  • 37
  • 68
0

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!

Vijay Singh
  • 277
  • 1
  • 3
  • 15