错误“Uncaught TypeError:无法在网格数据源中读取未定义的属性'__count'

时间:2016-10-27 07:58:02

标签: javascript kendo-ui

我最近更新了我的jQuery和Kendo UI版本。现在使用jQuery 1.12.13和Kendo UI 2016.3.914(不确定它在公共网站中对应哪个版本,但可能在2016年左右)。

似乎kendo或jQuery对数据格式有了更严格的要求。我有一个kendo UI Grid,其数据源为type: "json"。这适用于早期版本但不再适用 - 它发出警告:

Unknown DataSource transport type 'json'. Verify that registration scripts for this type are included after Kendo UI on the page.

所以我查看了文档并将类型更改为odata。 这给出了一个错误:

VM94003:3 Uncaught TypeError: Cannot read property '__count' of undefined

典型的Kendo UI,此错误消息实际上并没有告诉您太多。那有什么不对?

2 个答案:

答案 0 :(得分:2)

我将以下代码添加到dataSource的模式中,并且无需将类型移除为odata即可使用此工具。

schema: {
         data: function(data) {
              return data.value;
         },
         total: function(data) {
              return data['odata.count'];

         }

        }

link

中找到了解决方案

答案 1 :(得分:1)

事实证明,以某种方式将类型定义为odata需要数据源数据包含有关结果大小的信息。我尝试在网格的schema中添加一个定义:

total: function (data) {
    return data.length;
}

但这没有帮助。

最终,有什么帮助完全取消了type定义。所以现在我的网格数据源没有明确的type定义,但似乎工作正常。