How to pass more than one parameter to onChange action for select element in Ember2.3

I have a select element inside the loop, and the action I want to start must have two parameters: the selected parameter of the select element and the element we are looping. My code looks like this:

{{#each loopItems as |loopItem|}}
 <select onChange={{action 'fireThis' loopItem target.value }}> 
  {{#each loopItem.subItems as |subItem|}}
    <option value={{subItem.id}}>{{subItem.value}}</option>
  {{/each}}
 </select>
{{/each}}

And my fireThis action looks like this:

fireThis:function(loopItem, value){
 //Do something here with both. 
 // like loopItem.set('thisProperty', value);
}

Thus, in my particular case, the number of subtypes is dynamic, and I need to use the selected subItem with the loopItem element that it is currently located.

Prohibition of reorganization into components (right now, I can’t do this), how would I pass more than one parameter to an action running on 'onChange'?

I tried:

<select onChange={{action 'fireThis' value ="loopItem target.value" }}> 
<select onChange={{action 'fireThis' value ="loopItem target.value" }}>
<select onChange={{action 'fireThis' loopItem value="target.value"}}>
<select onChange={{action 'fireThis' value="target.value" loopItem}}>

undefined ( ). , :

<select onChange={{action 'fireThis' value="target.value"}}>

subItem, loopItem.

, loopItems Ember Objects, ID, . .

+4
4

, : ember 2 .

OP :

<select onChange={{action (action 'fireThis' loopItem) value="target.value"}}>

0

:

<select onChange={{action 'fireThis' loopItem}}>

fireThis:function(loopItem){
 var value = this.$('option:selected').val();
 //Do something here with both. 
 // like loopItem.set('thisProperty', value);
}
+1

- , - . loopitem + , , value = "target.value".

:

{{#each loopItems as |loopItem|}}
   {{loop-item-component loopItem=loopItem}}
{{/each}}

-

// Loop-item-component

    <select onChange={{action 'fireThis' value='target.value' }}> 
      {{#each loopItem.subItems as |subItem|}}
        <option value={{subItem.id}}>{{subItem.value}}</option>
      {{/each}}
    </select>

, , :

actions:{
 ...
    fireThis:function(value){
      let loopItem = this.get('loopItem');
      // Do something here with both. 
      // like loopItem.set('thisProperty', value);
    }
}

, , ; , , .

0

, value="target.value". , target.value event .

<select onchange={{action 'fireThis' loopItem}}>

and in firethis, you get loopItemand the eventobject in the parameter.

actions:{
 firethis(loopItem,event)
 {
  //let selectedValue= event.tager.value;
 }
}
0
source

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


All Articles