Ember 2 Parameters In A Action Of A Select Menu
I'm trying to pass more than one argument in an ember action. The problem is that one of the arguments is value='target.value' and apparently Ember doesn't like to add a second one
Solution 1:
To accomplish this you must use closure actions. Reference to Invoking Action
Controller
exportdefaultEmber.Controller.extend({
appName: 'Ember Twiddle',
selectorsData: [
{ name: 'mike', value: '1', action: 'alert', options: ["1", "2"] },
{ name: 'steve', value: '2', action: 'alert', options: ["1", "2"] }
],
actions: {
alert(value, name, target) {
alert("Hello: " + value + " - " + name + "-" + target);
}
}
});
Template
<h1>Welcome to {{appName}}</h1><br><br>
{{outlet}}
<br><br>
{{#each selectorsData as |selectorItem|}}
<label>{{selectorItem.name}}</label><selectonchange={{action (actionselectorItem.actionselectorItem.valueselectorItem.name) value="target.value"}}>
{{#each selectorItem.options as |option|}}
<optionvalue={{option}}>{{option}}</option
{{/each}}
</select><br>
{{/each}}
Solution 2:
Try something like this:
<select onchange={{action selectorItem.action target.value selectorItem.name}}>
....
yourAction: function(targetValue, selectorItemName) {..}
Here's an example: http://jsfiddle.net/nvfm3yz1/
Post a Comment for "Ember 2 Parameters In A Action Of A Select Menu"