事件嵌套CompositeView中的处理 [英] Event handling in nested compositeView

查看:190
本文介绍了事件嵌套CompositeView中的处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是相同的结构,在对此问题的回答说明 - > <一个href=\"http://stackoverflow.com/questions/13575101/how-to-handle-nested-compositeview-using-backbone-marionette/32787508?noredirect=1#comment53426646_32787508\">How使用Backbone.Marionette处理嵌套CompositeView中?
渲染我复合的观点和看法项。我的项目视图由LI标签。我想处理事件单击此ItemView控件。我想我的code如下:这是不工作同样的事件code片断如果我在我的第一个复合视图写,它获得的触发。但事件不会被触发的ItemView控件。请帮助。

  VAR topNavMenuView = Backbone.Marionette.ItemView.extend({
           标签名:礼,
           产品类别:下拉菜单,
           模板:_.template(topNavMenuItemTemplate)           初始化:功能(选件){
           的console.log(初始化);
            this.id = options.menu code;
          },
          事件:{
             点击礼:函数(事件){
                  警报('点击');
              },
             点击:函数(事件){
                             警报('点击');
             }
            }         });


解决方案

查看 事件 应该返回事件哈希像这样

 事件:{
    '点击':'的onClick
},
的onClick:功能(){
    警报('点击');
}

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');
             }
            }

         });

解决方案

View events should return events hash like this

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

这篇关于事件嵌套CompositeView中的处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆