html:(生成我的knockoutmvc)
<select class="span12" data-bind="options : VehicleManufacturers,optionsText : function(item) { return item.Name; },optionsCaption : 'Select Manufacturer...',value : VehicleManufacturer"
id="VehicleManufacturer">
<option value="">Select Manufacturer...</option>
<option value="">AUDI</option>
</select>
<span data-bind="with: VehicleManufacturer">
<span data-bind="text: Name"></span>
</span>
脚本:
var viewModelJs = {
"VehicleManufacturers": [{
"Id": 5,
"Name": "AUDI"
}],
"VehicleManufacturer": null
};
var viewModel = ko.mapping.fromJS(viewModelJs);
ko.applyBindings(viewModel);
viewModel.VehicleManufacturer = ko.computed({
read: function () {
return viewModel.VehicleManufacturer;
},
write: function (manufacturer) {
// Populate Model list routine
},
owner: viewModel
});
JsFiddle:http: //jsfiddle.net/ryDjs/2/
我可能不太正确地进行绑定,我想要实现的是根据本文的下拉级联,它与上面的代码一起使用,除了"with: VehicleManufacturer"
绑定,即未显示所选制造商的名称。