admin管理员组文章数量:1328380
In template:
<button {{action someAction someParameter}}>Some Action</button>
In controller:
someAction: function (e, someParameter) {
console.log(e, someParameter);
}
someParameter
is undefined as well as e
where I excepted to be event object.
How to pass parameter to action? If not possible does it mean I need to create Ember.View
to handle action with parameter?
In template:
<button {{action someAction someParameter}}>Some Action</button>
In controller:
someAction: function (e, someParameter) {
console.log(e, someParameter);
}
someParameter
is undefined as well as e
where I excepted to be event object.
How to pass parameter to action? If not possible does it mean I need to create Ember.View
to handle action with parameter?
- could you create a fiddle/bin with your code? – flash Commented Apr 2, 2013 at 10:02
1 Answer
Reset to default 9The only problem I see in your code is that the event object is not passed to the function in the controller when using the {{action}} helper. Regardless of that, your code should log the value of someParameter
to the console. If you are getting two undefined
maybe someParameter
is not within the context of the template, or it is undefined
.
Make sure someParameter
is there and holds the correct value, for example:
Template:
<button {{action someAction someParameter}}>Some Action (param: {{someParameter}} ) </button>
If the value doesn't show up, try view.someParameter
depending on how you are rendering the template, if you show your code we might be able to help you more.
On the controller:
someAction: function (someParameter) {
console.log(someParameter);
}
Hope this helps!
本文标签: javascriptHandling action parameter in EmberjsStack Overflow
版权声明:本文标题:javascript - Handling action parameter in Ember.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742215970a2434572.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论