0
我有兩段代碼。是否有可能在數據綁定上同時使用模板和值?
代碼#1:
<select data-bind="options: operatingSystems,
optionsText: function (item) {
return item.Name
},
value: selectedOperatingSystem"></select>
代碼#2:
<script type="text/html" id="os-template-detail">
<option data-bind="text: Name" class="body-text"></option>
</script>
<select data-bind="value: selectedOperatingSystem,
template: { name: 'os-template-detail', foreach: operatingSystems }"></select>
從JSON兩個節目數據正確。使用代碼#1時,當我在列表中選擇一個項目時,它會更新值,而代碼#2在更改項目時不更新任何內容。
我對Knockout.js很陌生,不知道Code#2爲什麼不起作用。 Knockout的限制是否阻止我同時使用模板和值?
@DhanaKrishnasamy我使用模板來呈現它的選項。我還更新了我的問題以包含更多代碼。 :) – Anonymous
請提供一個jsfiddle!因爲在這裏你的代碼似乎工作得很好:http://jsfiddle.net/C4beK/ – nemesv
是的,它的工作原理http://jsfiddle.net/dhanasekaran/JcV2b/ –