1

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.

How can I pass these two parameters? value='target.value' works if I only need one argument.

I've tried to write it this way but category is undefined.

{{#each selectorsData as |selectorItem|}}
<select onchange={{ action selectorItem.action value='target.value' category='selectorItem.name' }}>

I've tried this way too, but Ember gives me an error

{{#each selectorsData as |selectorItem|}}
   <select onchange={{ action selectorItem.action value='target.value' selectorItem.name }}>

 Error: Parse error on line 4:
 ....value' selectorItem.name }}>
Wesley
  • 155
  • 1
  • 11

2 Answers2

3

To accomplish this you must use closure actions. Reference to Invoking Action

Controller

export default Ember.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>
   <select onchange={{action (action selectorItem.action selectorItem.value selectorItem.name) value="target.value"}}>
        {{#each selectorItem.options as |option|}}
        <option value={{option}}>{{option}}</option
      {{/each}}
   </select>
   <br>
{{/each}}

Twiddle

Mike Vasquez
  • 105
  • 5
0

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/

Pat Diola
  • 91
  • 2
  • 1
    Pat, thanks for your answer but it is still not working, your solution returns undefined for 'value' – Wesley Mar 29 '16 at 18:58