我创建了一个递归函数,它将以递归方式从共享点文档库中获取文件详细信息,但无法知道递归函数是已解决还是已完成</ p>
//function definition
getFiles = function getFiles(folderUrl) {
var deferred = $.Deferred();
try {
$pnp.sp.web.getFolderByServerRelativeUrl(folderUrl).expand("Folders, Files").get().then(function (r) {
r.Folders.forEach(function (item) {
//recursive call
getFiles(item.ServerRelativeUrl);
});
r.Files.forEach(function (item) {
console.log(item.ServerRelativeUrl);
allfilesrecursive.push(item);
});
deferred.resolve(allfilesrecursive);
}).catch(function (err) {
Errorlog(JSON.stringify(err), 'getFiles catch', 'TestFileUpload.js', fileuploaddetails.currentBrowserURL);
deferred.reject();
});
} catch (err) {
Errorlog(JSON.stringify(err), 'getFiles', 'TestFileUpload.js', fileuploaddetails.currentBrowserURL);
deferred.reject();
}
return deferred.promise();
}