我有一个带有可观察对象数组的视图模型和一个计算的 selectedObject。我正在尝试将 KendoListView 绑定到 selectedObject 中的可观察数组,但 ListView 没有得到更新。
这里有一个小提琴演示了这个问题:
HTML:
<div data-bind="kendoListView: { data: fruits, template: template, selectable:'single', change: function(e){ selectedId(this.select().index())} }" ></div>
<hr/>
<div data-bind="kendoListView: {data: selectedChoice.seeds, template: template2 }"></div>
<hr/>
Selected Id: <strong data-bind="text: selectedId"> </strong>
<hr/>
<pre data-bind="text: ko.toJSON(selectedChoice, null, 2)"></pre>
javascript:
var ViewModel = function() {
template = '<div>#=name#</div>';
template2 = '<div>Anything</div>';
fruits = ko.observableArray([
{ id: "0", name: "apple", seeds: [
{number: "1"},{number:"2"},{number:"3"}]
},
{ id: "1", name: "orange", seeds: [
{number: "11"},{number:"12"},{number:"13"}]
},
{ id: "2", name: "banana", seeds: [
{number: "21"},{number:"22"},{number:"23"}]
}
]);
selectedId = ko.observable();
selectedChoice = ko.computed(function() {
var id = selectedId();
if (id) {
return ko.utils.arrayFirst(fruits(), function(fruit) {
return fruit.id === id;
});
}
}, this);
};
ko.applyBindings(new ViewModel());
我很感激社区可以提供的任何支持!
谢谢