我提交供您考虑,这个小提琴:http: //jsfiddle.net/alexdresko/HFFUL/5/
HTML 中有两个相同的网格,但是当您单击“加载”按钮时,只会填充其中一个。
这是我自己对knockout的根本误解,还是jqxgrid的问题?
这是代码:
<a href="#" data-bind="click: load">Load</a>
<div class="aGrid" data-bind="jqxGrid: { source: Stuff().People, columns: [ {text: 'Name', datafield: 'Name'} ], autoheight: true, sortable: true, altrows: true, enabletooltips:true }"></div>
<div class="aGrid" data-bind="jqxGrid: { source: Stuff().People, columns: [ {text: 'Name', datafield: 'Name'} ], autoheight: true, sortable: true, altrows: true, enabletooltips:true }"></div>
var dataFromServer = {
People: ko.observableArray([{
Name: "George"
}, {
Name: "Scot"
}])
};
var viewModel = function () {
this.Stuff = ko.observable({});
this.load = function () {
this.Stuff(dataFromServer);
};
};
$(function () {
var vm = new viewModel();
ko.applyBindings(vm);
});