0

所有示例都在 page.load 事件中将 json 数据绑定到 simpleGrid,该事件将触发以计算列并显示 gridview。但在我的情况下,页面的初始加载不会显示gridview,并且单击使用ajax 返回数据集的按钮,然后绑定到simpleGrid。这是示例

小提琴

我试图订阅 observableArray ,但这并没有重新生成网格,有什么提示吗?谢谢!

function viewModel() {
var self = this;
self.queryResult = ko.observableArray();
self.update = function (data) {
    //this is an ajax call and return dateset back
    $.each(initialData, function (index, item) {
        self.queryResult.push(item);
    });
};
self.gridViewModel = new ko.simpleGrid.viewModel({
    data: self.queryResult,
    pageSize: 10
});

}
4

1 回答 1

0

You never defined any headers in your simple grid. I added like below

   self.gridViewModel = new ko.simpleGrid.viewModel({
   data: self.queryResult,
    columns: [
        { headerText: "Name", rowText: "name" },
        { headerText: "Sales ", rowText: "sales" },
        { headerText: "Price", rowText: function (item) { return "$" + item.price.toFixed(2) } }
    ],
    pageSize: 4
});

See the updated fiddle here

于 2013-08-07T08:19:52.023 回答