在一次 Ajax 调用中从多个列表共享点 REST API 中获取数据 [英] Fetch data from multiple list sharepoint REST API in one Ajax call
问题描述
How can we get data from multiple list by using sharepoint REST API in one call . I: want to get data and also want to use multiple list for searching data too. Is it possible to do this in one call if "YES" then how and if "NO" then what are the best solutions for getting data??
Thanks in advance..
First of all, SharePoint REST does not support request batching like CSOM does. That makes it impossible to make multiple REST calls in a single round trip to the service.
The good news that according to Office 365 business roadmap the feature:
CSOM Batching for Apps for SharePoint
This feature allows support for $batch requests in SharePoint's OData REST services. This allows apps to make multiple REST calls in a single round trip to the service.
is already in Development state. Hurray! Thanks to the Office Developer Platform UserVoice for that and specifically to Andrew Connell for creating a feature request
From another hand, Search Query API
could be used for querying multiple lists, for example the following search query:
contentclass:STS_ListItem AND ContentType:Task
will return all Task items.
JavaScript Example
The following example demonstrates how to utilize Search API using REST endpoint:
function searchTaskItems(webUrl,success, failure) {
var url = webUrl + "/_api/search/query?querytext='contentclass:STS_ListItem AND ContentType:Task'";
$.ajax({
url: url,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
success(data.d.query);
},
error: function (data) {
failure(data);
}
});
}
//print tasks
searchTaskItems(_spPageContextInfo.webAbsoluteUrl,
function(query){
var resultsCount = query.PrimaryQueryResult.RelevantResults.RowCount;
for(var i = 0; i < resultsCount;i++) {
var row = query.PrimaryQueryResult.RelevantResults.Table.Rows.results[i];
var taskName = row.Cells.results[3].Value;
console.log(taskName);
}
},
function(error){
console.log(JSON.stringify(error));
}
);
这篇关于在一次 Ajax 调用中从多个列表共享点 REST API 中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!