admin 管理员组文章数量: 1086019
I want to send extra information from my handlebars script to my controller; this is my code:
<a {{action "resetState" data="state1" }}>reset1 </a>
I can't retrieve state1 in my controller; how do I send extra strings to the backend?
I want to send extra information from my handlebars script to my controller; this is my code:
<a {{action "resetState" data="state1" }}>reset1 </a>
I can't retrieve state1 in my controller; how do I send extra strings to the backend?
Share Improve this question asked Dec 2, 2012 at 6:05 AbdulFattah PopoolaAbdulFattah Popoola 9472 gold badges13 silver badges22 bronze badges3 Answers
Reset to default 5The API says you can pass in multiple parameters.
html and handlebars:
{{officename}}
<button {{action "actionTest" "hello" "goodbye" officename}}>See parameters through action in the console</button>
controller:
actionTest: function(a, b, c){
console.log(a);
console.log(b);
console.log(c);
},
See it in action in this jsbin
You can pass one or more context objects to the action handler by including them after the name of the action, like so:
{{action resetState state1}}
You will probably also need to specify a target (target="MyApp.someObject", or target="this") unless you want the action to go to your router. If you do want your router to get the message, you'll either need to send it a defined object and have the dynamic segment be :objectname_id to get an object out of it, or use the deserialize method.
route: '/service/:some_dynamic_segment',
deserialize: function(router, params) {
//params should equal {some_dynamic_segment: 'whatever you passed in'}
}
If you do send the action to a place other than your router, keep in mind that other events are all intercepted by the view, not the controller, in case you want to keep all that stuff together.
本文标签: javascriptPassing in parameters to controllers from Ember handlebar actionsStack Overflow
版权声明:本文标题:javascript - Passing in parameters to controllers from Ember handlebar actions - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744004564a2517049.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论