在一次 Ajax 调用中从多个列表共享点 REST API 中获取数据

编程入门 行业动态 更新时间:2024-10-27 12:28:08
本文介绍了在一次 Ajax 调用中从多个列表共享点 REST API 中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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 中获取数据

本文发布于:2023-10-29 12:55:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539747.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   数据   列表   Ajax   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!