Ember 2 in action selection menu

I am trying to pass a few arguments in an ember action. The problem is that one of the arguments is value = 'target.value', and apparently Ember doesn't like to add the second.

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

I tried to write it this way, but the category is undefined.

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

I tried 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 }}>
0
source share
2 answers

To do this, you must use the closing actions. Link to the calling 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

+2
source

Try something like this:

<select onchange={{action selectorItem.action target.value selectorItem.name}}>

....

yourAction: function(targetValue, selectorItemName) {..}

: http://jsfiddle.net/nvfm3yz1/

0

Source: https://habr.com/ru/post/1628373/


All Articles