我对knockoutjs很新。我尝试从[knockout js sample](http://knockoutjs.com/documentation/options-binding.html)稍微修改一下,但它不起作用。
<select data-bind="option: availCustomers, optionsText: 'CustomerName',
value: selectedCustomer, optionsCaption: '--- Choose ---'">
</select>
和viewmodel:
<script>
function customerViewModel() {
var self = this;
self.availCustomers = ko.observableArray();
self.selectedCustomer = ko.observable();
};
var Customer = function (id, name) {
this.CustomerId = id;
this.CustomerName = name;
};
$(document).ready( function() {
var cvm = new customerViewModel();
cvm.availCustomers = new ko.observableArray([
new Customer("12345", "ABC"),
new Customer("54321", "XYZ")
]);
ko.applyBindings(cvm);
});
</script>
所以请指导我
答案 0 :(得分:0)
我认为这只是一个错误的错误,bind的参数叫做“options”。
<select data-bind="options: availCustomers, optionsText: 'CustomerName',
value: selectedCustomer, optionsCaption: '--- Choose ---'">
</select>