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

javascript - Handling action parameter in Ember.js - Stack Overflow

programmeradmin7浏览0评论

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?

Share Improve this question asked Apr 2, 2013 at 4:21 Wojciech BednarskiWojciech Bednarski 6,3739 gold badges50 silver badges75 bronze badges 1
  • could you create a fiddle/bin with your code? – flash Commented Apr 2, 2013 at 10:02
Add a ment  | 

1 Answer 1

Reset to default 9

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

发布评论

评论列表(0)

  1. 暂无评论