カスタム セル テンプレートを使用して KoGrid セルにドロップダウン リストを表示しようとしていますが、正常に動作しない理由がわかりません。
を使用した実際のドロップダウン リストの例がoptions, optionsText, optionsValue and optionsCaption
あり、バインディングは正常に機能します。しかし、KoGrid の同様のドロップダウンには要素が表示されません。私の質問は、何が欠けている/間違っているのか、どうすればこの問題を解決できますか?
jsFiddle へのリンク: http://jsfiddle.net/AxyWz/6/
HTML:
<p>
Working drop-down list:
<select data-bind="options: data, optionsText: 'name', optionsValue: 'id', optionsCaption: '-', value: selectedItemId"></select>
</p>
<p>
Drop-down list not working in KoGrid:
<div class="grid" data-bind="koGrid: gridOptions"></div>
</p>
<pre data-bind="text: ko.toJSON($root, null, 2)"></pre>
<script type="text/html" id="template">
<select data-bind="options: $root.data, optionsText: 'name', optionsValue: 'id', optionsCaption: '-', value: $parent.entity[$data.field]"></select>
</script>
Javascript:
function Item(id, name) {
this.id = ko.observable(id);
this.name = ko.observable(name);
this.parentId = ko.observable();
}
function ViewModel() {
this.selectedItemId = ko.observable();
this.data = ko.observableArray([
new Item(1, 'aaa'),
new Item(2, 'sss'),
new Item(10, 'xxx'),
new Item(14, 'zzz')
]);
this.gridOptions = {
data: this.data,
canSelectRows: false,
columnDefs: [
{ field: 'id', displayName: 'id' },
{ field: 'name', displayName: 'name' },
{
field: 'parentId', displayName: 'parent',
cellTemplate: $.trim($('#template').html())
},
]
};
}
ko.applyBindings(new ViewModel());