Get selected parameter value in change event

I have a dropdown with the following attributes:

 <select value.bind="row.columns[$parent.$index].colSize" change.delegate="changeColumnSize($parent.$index, $index, row.columns[$parent.$index].colSize)"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> 

But it seems that I cannot pass row.columns[$parent.$index].colSize as a parameter. It is always undefined .

How to pass the selected value of the dropdown list directly to the change event method?

+5
source share
1 answer

You are missing the .bind value in your selection options. I prefer to use mode.bind instead of value.bind. Try something like this:

 <template> <select value.bind="changedValue" change.delegate="DropdownChanged(changedValue)"> <option model.bind="1">1</option> <option model.bind="2">2</option> <option model.bind="3">3</option> <option model.bind="4">4</option> </select> </template> export class App { changedValue; DropdownChanged(changedVal) { alert(changedVal); } } 

I'm not sure what you are trying to bind to a selection, but basically you want to create a variable that you can also bind to the selected value. Thus, the selected value will be set to the variable changedValue . I like to use model.bind because I can bind true / false values ​​instead of everything that is a string.

I made a running Gist for you if needed: https://gist.run/?id=87f6897928feb504dad638d439caf92f

+10
source

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


All Articles