gpt4 book ai didi

javascript - JQGrid 4.3.2 读取JSON数据时getAccessor函数出错

转载 作者:行者123 更新时间:2023-11-30 13:20:15 26 4
gpt4 key购买 nike

我一直在尝试在 JQGrid 中呈现 JSON 数据。我收到以下错误:

Error: b is undefined
Source File: http://localhost:1302/Scripts/jquery.jqGrid.min.js
Line: 23

当我使用未最小化的 JQGrid 源代码时,我看到它对 getAccessor 方法进行了多次调用,并且在最后一次调用方法 (obj) 的第一个参数时传递了一个未定义的值:

Error: obj is undefined
Source File: http://localhost:1302/Scripts/jquery.jqGrid.src.js
Line: 151

这似乎是导致网格停止渲染的原因,但为什么呢?

呈现的网格显示列标题但没有内容。网格中的“正在加载...”消息永远不会消失。

我的 JSON 数据如下所示:

{
"total":"1",
"page":"1",
"userdata":{

},
"records":"2",
"rows":[
{
"DateOfBirth":"11/04/2012 12:00:00 AM",
"DisambiguationNote":"Boring guy",
"FirstName":"Joe",
"LastName":"Bloggs",
"MiddleName":"Binkie",
"PersonId":"1"
},
{
"DateOfBirth":"01/01/2001 12:00:00 AM",
"DisambiguationNote":"someone else",
"FirstName":"Edna",
"LastName":"Edwards",
"MiddleName":"Edith",
"PersonId":"8"
}
]
}

我的网格代码如下所示:

$(function () {
$("#persongrid").jqGrid({
url: '/Person/List',
datatype: 'json',
mtype: 'GET',
jsonreader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
id: "5" ,
cell: "" ,
userdata: "userdata"
},
colModel: [
{ name: 'DateOfBirth', index: 'DateOfBirth',sorttype:'date' },
{ name: 'DisambiguationNote', index: 'DisambiguationNote' },
{ name: 'FirstName', index: 'FirstName' },
{ name: 'LastName', index: 'LastName' },
{ name: 'MiddleName', index: 'MiddleName' },
{ name: 'PersonId', index: 'PersonId',sorttype:'int' }
],
pager: '#persongridpager',
rowNum: 10,
rowList: [10, 20, 30],
viewrecords: true,
gridview: true,
caption: 'People'
});
});

我可以看到 JSON 数据正在从 AJAX 请求中检索,我已经非常仔细地阅读了 JQGrid 的 JSON 数据说明,但看​​不出我做错了什么。

有人可以帮忙吗?谢谢。

最佳答案

错误很容易,但很难发现:您使用 jsonreader 而不是 jsonReader 所以 jsonreader 将被忽略并将使用默认的 jsonReader

如何查看 the demo修改后数据读取成功。

顺便说一句,您可以只指定与默认值不同的 jsonReader 属性并使用

jsonReader: {
repeatitems: false,
id: "5",
}

jsonReader: {
repeatitems: false,
id: "PersonId",
}

我在演示中添加了 height: 'auto' 选项只是为了提高可见性。

关于javascript - JQGrid 4.3.2 读取JSON数据时getAccessor函数出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10474592/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com