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.