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
Post a Comment