Event handling in nested compositeView

2019-09-11 23:17发布

I am using the same structure as explained in the answers for this question -- > How to handle nested CompositeView using Backbone.Marionette? to render my composite views and Item view. My Item view consists of LI tag. I want to handle click event for this Itemview. I am trying my code as below :which is not working The same events code snippet If I write in my first composite view, It get's triggered. But events do not get triggered in ItemView. Please help.

var topNavMenuView = Backbone.Marionette.ItemView.extend({
           tagName :'li',
           className:'dropdown',
           template : _.template(topNavMenuItemTemplate) ,

           initialize:function(options){
           console.log("initialize");
            this.id=options.menuCode;
          },
          events: {
             'click li' : function(event){
                  alert('click');
              },
             'click ' : function(event){
                             alert('click');
             }
            }

         });

1条回答
混吃等死
2楼-- · 2019-09-12 00:05

View events should return events hash like this

events: {
    'click': 'onClick'
},
onClick: function(){
    alert('click');
}
查看更多
登录 后发表回答