1
votes

This question is a continuation of this..

I have an observable array as follows:

var myObservableArray = ko.observableArray([
    { name: "Bungle", type: "Unknown" },
    { name: "George", type: "Unknown" },
    { name: "Zippy", type: "Unknown" }
]); 

I fill up a select list box using the below code:

<select data-bind="options: myObservableArray,
                   optionsText: function(item) {
                       return item.name + '-' + item.type;
                   },optionsValue:'name',
                   value: selected"></select>

I need a method which can change the type of selected value to 'mytype' eg.. if Bungle is selected... { name: "Bungle", type: "mytype" }

Any help is sincerely appreciated.

1
You can check my answer on your original question: stackoverflow.com/questions/34453587/… - TSV

1 Answers

0
votes

You can check this jsfiddle illustrating changing of the selected object type via text input.

View model:

var viewModel = {
  myObservableArray: myObservableArray,
  selected: ko.observable()
};

And markup:

<!-- ko if: selected -->
<div>Type:</div>
<input data-bind="value: selected().type"/>
<!-- /ko -->