Event handling in nested compositeView

情到浓时终转凉″ 提交于 2019-12-25 14:08:52

问题


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:


View events should return events hash like this

events: {
    'click': 'onClick'
},
onClick: function(){
    alert('click');
}


来源:https://stackoverflow.com/questions/32795810/event-handling-in-nested-compositeview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!