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

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -