javascript - How to pass selected option using knockout to an observable array -


i trying pass selected value of drop down list view model using knockout js.

<select class="form-control" style="width:auto" data-bind="options: clients, optionscaption: 'choose...', optionstext: 'name', optionsvalue: 'value', value: 'selectedcustomer'"></select>

in view model, have declared ko observable store selected value:

self.selectedcustomer = ko.observablearray([]);

the variable not getting populated when select value. tips? thanks!

i can see 2 issues code:

you're binding value observablearray, selected option single customer observable should used instead.

the value (value: 'selectedcustomer') should not wrapped in single quotes because you're trying bind string rather observable.

try below:

<select class="form-control" style="width:auto" data-bind="options: clients, optionscaption: 'choose...', optionstext: 'name', optionsvalue: 'value', value: selectedcustomer"></select> 

then in view model:

self.selectedcustomer = ko.observable(); 

Comments

Popular posts from this blog

java - unable show chart in xls document using jasper reports -

java.lang.RuntimeException: Could not generate dummy secret at sun.security.ssl.RSAClientKeyExchange.<init> -

javascript - How to change image src on success AJAX -