我在一个页面上有一个Kendo Grid,它使用以下代码初始化:
$.post("@Url.Action("kendoGetJson", "MyOpsUser")", function (col) {
var grid = $("#grid").kendoGrid($.parseJSON(col));
var dataSource = new kendo.data.DataSource(
{
transport: {
read: {
url: '@Url.Action("MyTaskOpsPopulate", "MyOpsUser", new { filterType = "0", user = "toto", urgencyState = "{\"Urgent\":true,\"Standard\":true,\"OnHold\":true}" })',
contentType: "application/json",
dataType: "json"
}
},
schema: {
data: "Value"
},
type: "json",
serverPaging: false,
serverFiltering: true,
serverSorting: false
}
);
var grid = $("#grid").data("kendoGrid");
var dataSource = dataSource.read();
grid.setDataSource(dataSource);
}
网格定义如下:
{"height": 550,
"groupable": true,
"sortable": true,
"pageable": {
"refresh": true,
"pageSizes": true,
"buttonCount": 5
},
"columns": [
{
"field": "Titre"
},
{
"field": "Prix"
}
]}
我要绑定到网格的数据JSON:
{"Value": [
{
"Titre": "hey",
"Prix": 12
},
{
"Titre": "hello",
"Prix": 25
}
]}
我在控制台中收到以下错误:"未捕获的TypeError:无法读取属性' fetch'未定义"。
数据文件在网格加载后绑定,而不是在定义文件中,因为我需要动态生成数据的JSON。
我无法弄明白如何让这项工作成功,如果有人可以提供帮助,那就太棒了......
答案 0 :(得分:1)
最后我找到了解决方法!
$ .post(" @ Url.Action(" kendoGetJson"," MyOpsUser")",function(col){
var grid = $("#grid").kendoGrid($.parseJSON(col));
$.post("@Url.Action("MyOpsUserPopulate", "MyOpsUser", new { filterType = "0", user = "toto", urgencyState = "{\"Urgent\":true,\"Standard\":true,\"OnHold\":true}" })", function (JsonData) {
var grid = $("#grid").data("kendoGrid");
var datasource = grid.dataSource;
datasource.data(JsonData);
});
这对我有用。谢谢你的帮助!