2
我有一个场景,我想使用REST API从多个文件夹中获取所有文件。我想以这种方式过滤数据,以便我可以忽略文件夹并仅提取所有文件中的文件。我有CAML查询来执行递归的所有活动,但是当我与REST API集成时,它会抛出错误的请求错误。我在IE中检查了网络标签,看起来好像我的代码中的查询没有从REST API返回任何数据,并且在使用“GetItems”时失败。有人可以让我知道如何在REST API中集成CAML查询。使用REST API和CAML查询在单个REST调用中获取多个文件夹中的文件
var getContent = function (listTitle) {
var deferred = $q.defer();
if (listTitle == 'CandidateReports') {
var query = appweburl + "_api/SP.AppContextSite("+ hostweburl +")/web/lists/GetByTitle('" + listTitle + "')/GetItems";
var executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: query,
method: "POST",
headers: {
"Accept": "application/json; odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose"
},
data: JSON.stringify({
query: {
__metadata: {
type: "SP.CamlQuery"
},
ViewXml: "<ViewFields><FieldRef Name='FileLeafRef' /> <FieldRef Name='Title' /> </ViewFields> <QueryOptions> <ViewAttributes Scope='RecursiveAll' /> </QueryOptions> <Where> <Eq> <FieldRef Name='FSObjType' /> <Value Type='Integer'>0</Value> </Eq> </Where>"
}
}),
success: function (data, textStatus, xhr) {
console.log(data);
deferred.resolve(JSON.parse(data.body));
},
error: function (xhr, textStatus, errorThrown) {
deferred.reject(JSON.parse(xhr.body).error);
}
});
return deferred.promise;
};
return {
getContent: getContent
};
您是否找到解决方案?我也试图将CAML实现为Angular $ http方法... – Anton