2013-05-13 34 views
4

如果您在Chrome中運行此提琴,選擇框中將正確填充選項A,B和C.但是,如果您使用Internet Explorer(版本8或9)運行它,這是行不通的。我怎樣才能修復這個小提琴使它與Internet Explorer一起工作,但仍然使用虛擬元素?敲除虛擬元素不適用於Internet Explorer

http://jsfiddle.net/jeljeljel/2tUmP/

HTML

<script type="text/html" id="template"> 
    <select id="type" name="type"> 
     <option value="">-- Choose --</option> 
     <!-- ko foreach: types --> 
     <option data-bind="text: $data.desc, attr: { value: $data.id }"></option> 
     <!-- /ko --> 
    </select> 
</script> 
<div id="placeholder" data-bind="template: { name: 'template' }"></div> 

的Javascript

function Model(){ 
    var self = this; 
    self.types = ko.observable([]); 
} 
var model = new Model(); 
model.types().push({id: 0, desc:'A'}); 
model.types().push({id: 1, desc:'B'}); 
model.types().push({id: 2, desc:'C'}); 

ko.applyBindings(model); 

回答

5

這可能是Internet Explorer的一個限制。

而不是虛擬的元素,用options結合來填充<select>元素:

<select id="type" name="type" 
    data-bind="options: types, optionsText: 'desc', optionsValue: 'id', optionsCaption: '-- Choose --'"> 
</select> 

文檔:http://knockoutjs.com/documentation/options-binding.html

+1

應該指出的是,限制只能在'