我是淘汰赛的新手,并尝试了我认为是一个简单的场景,但它只是不起作用。Neither of the two input's changes when the selection changes, and the select list does not initialise to the selectedFormat.
HTML:
<input type="text" data-bind="value: selectedFormat.id" />
<input type="text" data-bind="enable: selectedFormat.fields()[0].enabled" />
<select data-bind="options: formats, optionsText: 'name', value: selectedFormat" />
JS:
var data = {
formats: [
{ id: 1, name: 'Format 1', fields: [
{ id: 1, enabled: true },
]},
{ id: 2, name: 'Format 2', fields: [
{ id: 1, enabled: false },
]}
],
selectedFormat:
{ id: 2, name: 'Format 2', fields: [
{ id: 1, enabled: false },
]}
}
var vm = ko.mapping.fromJS(data);
ko.applyBindings(vm);