Why does the option text get converted to a string of a function after the values has been updated from ko.mapping.fromJS?
Sample: 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);
Notice that after update has been pressed the option text becomes a function.