2014-01-28 73 views
0

我對knockoutjs很陌生。我嘗試從[knockoutjs示例](http://knockoutjs.com/documentation/options-binding.html)修改一些,但它不起作用。knockoutjs select option not bind

<select data-bind="option: availCustomers, optionsText: 'CustomerName', 
value: selectedCustomer, optionsCaption: '--- Choose ---'"> 
</select> 

和視圖模型:

<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> 

所以請指導我

+1

沒有工作是不夠的。錯誤消息和結果。理想情況下,一個JsFiddle演示問題 – GraemeMiller

+0

看起來很好,像這樣http://jsfiddle.net/WN2y6/乾杯 –

+0

剛試過jsfiddle。結果與我的瀏覽器相同:顯示空的下拉列表 – hansen168

回答

0

我認爲這僅僅是一個mispeling錯誤,綁定的參數被稱爲 「選項」。

<select data-bind="options: availCustomers, optionsText: 'CustomerName', 
value: selectedCustomer, optionsCaption: '--- Choose ---'"> 
</select>