我试图在下拉列表中显示一个可观察的数组,当用户选择该选项时,我想呈现该视图模型的属性.看起来很简单.我提供了代码和Fiddle的链接.
HTML:
<select data-bind="options: oCountries,
optionsText: 'name',
optionsValue: 'isocode',
value: selectedCountry">
</select>
Controlled by <span data-bind="value: selectedCountry.isocode"></span>
Run Code Online (Sandbox Code Playgroud)
JS:
var countries = [{
"name": "Afghanistan",
"isocode": "AF",
"language": "English",
"crmdatacontroller": "CRM India"
}, {
"name": "Aland Islands",
"isocode": "AX",
"language": "Finnish",
"crmdatacontroller": "CRM Finland"
}]
var viewModel = {
oCountries: ko.observableArray(countries),
selectedCountry: ko.observableArray(['AX'])
};
ko.applyBindings(viewModel);
Run Code Online (Sandbox Code Playgroud)
另见这个小提琴