2014-04-17 105 views
2

我正在使用jQuery的WebPart頁面上工作,我打算將jqGrid也納入到頁面中。該網頁將在grid.i加載所有列表項得到了阿賈克斯的響應,但數據不會顯示網格此選項將顯示一條消息「沒有記錄查看」無法在JqGrid中加載SharePoint列表項REST API響應

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" 
},..... 

讓我知道我做錯了什麼。 任何幫助將不勝感激。謝謝。

回答

6

我在這裏回答我自己的問題,以防有人跑過類似的東西。這是一個Ajax調用MS JSON返回列表數據的MS SharePoint站點。只有一件事是在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中。