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?

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!

本文标签: javascriptHandling action parameter in EmberjsStack Overflow