从SPO(SPFx)中的列表中获取附件需要很长时间



我在SPFx for SharePoint Online中有一个web部件,它显示列表项和这些列表项上的任何附件。代码似乎需要相当长的时间(每个附件可能需要三分之一秒(

有什么办法可以加快速度吗?

谢谢P

ViewXml: this.properties.camlQuery,
});

// look through the returned items.
for (var i = 0; i < r.length; i++) {

console.log('ID:' + r[i]["ID"]);

//const item: IItem = sp.web.lists.getByTitle(this.properties.listName).items.getById(Number(r[i]["ID"]));
console.log('got by id');
// get all the attachments
const attachmentInfo: IAttachmentInfo[] = await item.attachmentFiles();
console.log('got attachmentInfo');
attachmentInfo.map(file=>{
var fileUrl=file.ServerRelativeUrl;
console.log('fileUrl:' + fileUrl);
})

尝试批处理:https://pnp.github.io/pnpjs/concepts/batching/

它只是将多个请求打包到一个请求中,这样你就可以一次获得所有物品的数据(使用一个SP请求,也就是(

const [batchedSP, execute] = sp.batched();
for (var i = 0; i < r.length; i++) {
const item = batchedSP.web.lists.getByTitle(this.properties.listName).items.getById(Number(r[i]["ID"]));
item.attachmentFiles().then(attachmentInfo => {
console.log('got attachmentInfo');
// do something with attachment info
}
}
await execute(); // <<< the real request is sent here

最新更新