网格数据源出现错误“Uncaught TypeError: Cannot read property '__count' of undefined”

7

我最近升级了jQuery和Kendo UI版本,现在使用的是jQuery 1.12.13和Kendo UI 2016.3.914(不确定对应其公共网站的哪个版本,但可能在R3 2016左右)。

似乎kendo或jQuery对数据格式更加严格了。 我有一个带有type:“json”的数据源的kendo UI Grid。 这在早期版本中有效,但现在不再有效 - 它会发出以下警告:

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个回答

5
我将以下代码添加到数据源的模式中,并使其工作而不删除类型 odata
schema: {
         data: function(data) {
              return data.value;
         },
         total: function(data) {
              return data['odata.count'];

         }

        }

在这个链接中找到了解决方案。


3

事实证明,将类型定义为odata会期望数据源包含有关结果大小的信息。我尝试在网格的schema中添加了一个定义:

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

但这并没有起到帮助的作用。

最终,真正起到作用的是完全去掉了type定义。所以现在我的网格数据源没有显式的type定义,但它似乎工作得很好。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接