传递参数到骨干视图的骨干事件对象 [英] Passing parameters into the Backbone events object of a backbone view

查看:98
本文介绍了传递参数到骨干视图的骨干事件对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个骨干查看下列事件。它的一个产品视图 - 三个选项卡(全部,前3名,五大)

我可以以某种方式传递参数到方法声明,使其等同于以下(不工作)?

 事件:{
        点击#顶级全:新产品推荐(1)
        点击#前三名:新产品推荐(2)
        点击#前十:新产品推荐(3)
    },
    新产品推荐(OBJ){
      //做基于OBJ价值的东西
    }


解决方案

您可以把额外的参数上,而不是可点击的项目数据属性;是这样的:

 <一个ID =顶所有数据煎饼=1>

然后新产品推荐可以自己搞明白:

 新产品推荐:功能(EV){
    VAR煎饼= $(ev.currentTarget)。数据('煎饼');
    //并继续我们仿佛称为新产品推荐(煎饼)
    // ...
}

I have the following events for a Backbone View. Its a product view - with three tabs ("All", "Top 3", "Top 5")

Can I somehow pass a parameter into the method declaration so that it is equivalent to the following (this doesn't work)?

    events : {
        "click #top-all":          "topProducts(1)"
        "click #top-three":      "topProducts(2)"
        "click #top-ten":         "topProducts(3)"
    },
    topProducts(obj){
      // Do stuff based on obj value
    }

解决方案

You could put the extra argument in a data attribute on the clickable item instead; something like this:

<a id="top-all" data-pancakes="1">

And then topProducts can figure it out itself:

topProducts: function(ev) {
    var pancakes = $(ev.currentTarget).data('pancakes');
    // And continue on as though we were called as topProducts(pancakes)
    // ...
}

这篇关于传递参数到骨干视图的骨干事件对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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