如何使用Ember.Button传递参数?

时间:2014-03-20 08:32:22

标签: ember.js

在我正在处理的Ember.js应用程序中,我想将参数从模板传递给控制器​​函数但不能。

模板

{{#view Ember.Button target="MyApp.Controller" action="start"}}

{{/view}}

控制器

App.MyAppClass = Ember.Controller.extend({
    actions: {
        start: function(arg) {
            console.log(arg);
        }
    }
});

有没有人习惯遇到这个问题?

1 个答案:

答案 0 :(得分:2)

您确定要引用正确的控制器吗?

我刚用 -

进行了快速模拟测试
/** templates/foobar.hbs **/
<button {{action "foo" "bar"}}>Foobar</button>

/** controllers/foobar.js **/
var FoobarController = Ember.Controller.extend({
    actions: {
       foo: function (args) {
           alert(args); // getting an alert with "bar"
       },
    }
});

我建议阅读 - http://emberjs.com/guides/components/sending-actions-from-components-to-your-application/

{{#view Ember.Button target="MyApp.Controller" action="start" param="parameter"}}

{{/view}}