I'm sure I'm doing it wrong, but it seems that if the 'value' is the result of a mapping.fromJS, the binding will not select that value in the combo box.
I've capture my problem in this jsfiddle:
http://jsfiddle.net/88eLa/4/
I get from two separate URL the list of states (e.g. [{Id: 'CA', Name: 'California'},...]) and my model: { State: {Id: 'TX', Name: 'Texas'}}.
If my view-model is something like this:
function ViewModel() {
var self = this;
self.State = ko.observable();
self.ref = { States : [] }
// this doesn't work:
self.ref.States = statesJson;
ko.mapping.fromJS(modelJson, {}, self);
}
and neither does this:
...
var states = ko.mapping.fromJS(statesJson);
self.ref.States = states;
ko.mapping.fromJS(modelJson, {}, self);
By "doesn't work" I mean the combo gets populated, but the proper state never gets selected.
Sure, I can set it directly self.State(model.State), but if that's the answer, maybe I'm missing what the point/use-cases for ko.mapping are?
(I think the problem stems from the ko.selectExtensions.writeValue, where "ko.selectExtensions.readValue(element.options[i]) == value" seems to always be false in both of the approaches above.)