gpt4 book ai didi

json - 无法在 JqGrid 中加载 SharePoint 列表项 REST API 响应

转载 作者:行者123 更新时间:2023-12-01 11:47:13 24 4
gpt4 key购买 nike

我正在开发一个使用 jQuery 的 WebPart 页面,我还计划将 jqGrid 合并到该页面中。该页面将加载网格中的所有列表项。我得到了 ajax 的响应,但数据不会显示在网格中,它会显示一条消息“无记录 View ”

jQuery("#list2").jqGrid({

url:"https://xyz.sharepoint.com/sites/Live/_vti_bin/ListData.svc/Region",
datatype: "json",
type: "GET",
contentType: 'application/json;odata=verbose',
ajaxGridOptions: { contentType: "application/json; charset=utf-8" },
colNames:["Country", "State", "City"],
colModel:[
{name:'Country',index:'Country', width:55},
{name:'State',index:'State', width:90},
{name:'City',index:'City', width:90}

],jsonReader : {
records: "__metadata",
cell: "",
repeatitems: false
},
rowNum: 3,
gridview: true,
pager: '#pager2',
autoencode: true,
viewrecords: true,
height: "auto",
ignoreCase: true,
hidegrid: false
});
</Script>

这是我得到的Json,

{
"d" : {
"results": [
{
"__metadata": {
"uri": "https://xyz.sharepoint.com/sites/Live/_vti_bin/ListData.svc/Region(1)", "etag": "W/\"1\"", "type": "Microsoft.SharePoint.DataService.RegionItem"

}, "ContentTypeID": "0x010071297C85CCC1654A942D938B605256CA", "Country": "Australia", "State": "New South Wales", "City": "Abbotsford", "Id": 1, "ContentType": "Item", "Modified": "\/Date(1397547577000)\/", "Created": "\/Date(1397547577000)\/", "CreatedBy": {
"__deferred": {
"uri": "https://xyz.sharepoint.com/sites/Live/_vti_bin/ListData.svc/Region(1)/CreatedBy"
}
}, "CreatedById": 9, "ModifiedBy": {
"__deferred": {
"uri": "https://xyz.sharepoint.com/sites/Live/_vti_bin/ListData.svc/Region(1)/ModifiedBy"
}
}, "ModifiedById": 9, "Owshiddenversion": 1, "Version": "1.0", "Attachments": {
"__deferred": {
"uri": "https://xyz.sharepoint.com/sites/Live/_vti_bin/ListData.svc/Region(1)/Attachments"
}
}, "Path": "/sites/live/Lists/Region"
},.....

让我知道我做错了什么。任何帮助将不胜感激。谢谢。

最佳答案

我在这里回答我自己的问题,以防有人遇到类似的问题。这是对 MS SharePoint 站点的 ajax 调用,返回 JSON 中的列表数据。在 jsonReader 中只缺少一件事必须指定“d.result”而不是“_metadata”。所以最终完整的 java 脚本看起来像这样。

 jQuery("#list2").jqGrid({

url:"https://xyz.sharepoint.com/sites/Live/_vti_bin/ListData.svc/Region",
datatype: "json",
type: "GET",
contentType: 'application/json;odata=verbose',
ajaxGridOptions: { contentType: "application/json; charset=utf-8" },
colNames:["Country", "State", "City"],
colModel:[
{name:'Country',index:'Country', width:55},
{name:'State',index:'State', width:90},
{name:'City',index:'City', width:90}

],
jsonReader : {
records: "d.results",
cell: "",
repeatitems: false
},
rowNum: 3,
gridview: true,
pager: '#pager2',
autoencode: true,
viewrecords: true,
height: "auto",
ignoreCase: true,
hidegrid: false
});
</Script>

现在,这工作正常,列表数据成功加载到 jqGrid 中。

关于json - 无法在 JqGrid 中加载 SharePoint 列表项 REST API 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23127039/

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