【问题标题】:Ember Actions 2: Using Variables Action NamesEmber 操作 2:使用变量操作名称
【发布时间】:2014-08-04 21:41:53
【问题描述】:

我试图弄清楚如何将动作列表传递给模板并使用每个把手迭代这些动作中的每一个。

我想做的是这样的,其中列表变量在控制器中定义如下:

   App.CoolController = Em.ObjectController.extend({
    currentActions:['action1','action2'],
    actions:{
        action1: function(){
            alert('bar');
        },
        action2: function(){
            alert('baz');
        }
    });

模板可以像这样遍历它们:

{{#each currentAction in currentActions}}
    <div {{action currentAction model}}>currentAction</div>
{{/each}}

有人能做到吗?

【问题讨论】:

    标签: javascript ember.js dynamic-programming


    【解决方案1】:

    总的来说,我只是用你的代码做到了;)除了你缺少一个括号来关闭你的操作哈希。

    App.IndexController = Em.ObjectController.extend({
            currentActions:['action1','action2'],
            actions:{
                action1: function(model){
                    alert('bar ' + model);
                },
                action2: function(model){
                    alert('baz ' + model);
                }
            }
    });
    

    http://emberjs.jsbin.com/jutuba/1/edit

    【讨论】:

    • 我理解这个问题意味着两个动作都会在每个项目上触发,你有两个项目有两个单独的动作。
    • 哦,也许,我想知道他是不是在尝试使用车把助手。我们得看看。
    • 再次感谢各位...我想太多了! :)
    猜你喜欢
    • 2021-11-23
    • 2015-10-07
    • 2019-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多