rest - 当文件夹包含超过 5000 个文档时如何查询共享点在线数据
问题描述
我有一个 SharePoint 在线网站,其中一个文件夹有超过 5000 条记录。其余的 api 给出了错误。尝试的操作被禁止,因为它超过了列表视图阈值。如果是使用调用 - /_api/web/lists/getbytitle('Documents')/Items. 这工作正常,但我想要一个特定文件夹中的文档,因此我正在使用调用 - _api/web/GetFolderByServerRelativePath(),它给出了阈值错误。
有没有办法使用在线共享点的标题调用来获取文件夹数据。
注意 - 标题字段在在线共享点中被索引。
解决方案
您可以使用 GetFolderByServerRelativePath()。为了避免限制,您每次可以调用 5000 个项目,直到您获得所有数据(递归),使用 d.__next 属性:
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFolderByServerRelativeUrl('/folderName/innerFolder')/Files?$top=5000";
var response = []; // this variable is used for storing list items
GetListItems();
function GetListItems(){
$.ajax({
url: url,
method: "GET",
headers: {
"Accept": "application/json; odata=verbose"
},
success: function(data){
response = response.concat(data.d.results);
console.log(response);
if (data.d.__next) {
url = data.d.__next;
GetListItems();
}
},
error: function(error){
console.log(error);
}
});
}