, -. , , , . Knockout 3.0.0 ( , )
, , , @XGreen , , , .
, .
, .
[
{ id: 1, name: "one", choice: false },
{ id: 2, name: "two", choice: true },
{ id: 3, name: "three", choice: false }
]
, , true, .
, , .
optionsAfterRender options .
<select data-bind="options: choices,
optionsValue: 'name',
optionsAfterRender: $root.selectDefault">
</select>
, AfterRender , , , , choice , , .
, ko.applyBindingsToNode 2.2.0, .
function ViewModel(choices) {
this.choices = ko.observableArray(choices);
this.selectDefault = function(option,item){
if(item.choice){
ko.applyBindingsToNode(option.parentElement, {value: item.name}, item);
}
};
};
ko.applyBindings(new ViewModel(choices));
fiddle.