最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Passing in parameters to controllers from Ember handlebar actions - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

3 Answers 3

Reset to default 5

The 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.

发布评论

评论列表(0)

  1. 暂无评论