Why is the option text converted to a function string after the values have been updated from ko.mapping.fromJS?
Example: http://jsfiddle.net/tYnc6/24/
Html:
<div> <select data-bind="options: items, value: selected, optionsText: function(item) { return ('[' + item.Id + '] ' + item.Name) }, optionsCaption: 'Choose...'"></select> <button data-bind="click: update">Update</button> </div>
Javascript:
var mapping = { key: function(data) { return ko.utils.unwrapObservable(data.Id); } }; viewModel = { items: ko.observableArray([ {Name: 'foo', Id: '1'}, {Name: 'bar', Id: '2'} ]), selected: ko.observable(), update: function() { data = [ {Name: 'foo', Id: '1'}, {Name: 'bar', Id: '2'}, {Name: 'baz', Id: '3'} ]; ko.mapping.fromJS(data, mapping, this.items); } } ko.applyBindings(viewModel);
Please note that after the update has been clicked, the option text becomes a function.
source share