SharePoint Online PnPjs 批量更新项目
前言
最近,项目里需要批量更新项目,我们都知道On Promise的服务器端对象有一个好方法,不过,SharePoint Online里没有。
正文
好吧,其实找了很多API,然后发现PnPjs里面有个不错的方法,推荐给有需要的小伙伴!
import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/lists";
import "@pnp/sp/items";
let list = sp.web.lists.getByTitle("rapidupdate");
const entityTypeFullName = await list.getListItemEntityTypeFullName()
let batch = sp.web.createBatch();
// note requirement of "*" eTag param - or use a specific eTag value as needed
list.items.getById(1).inBatch(batch).update({ Title: "Batch 6" }, "*", entityTypeFullName).then(b => {
console.log(b);
});
list.items.getById(2).inBatch(batch).update({ Title: "Batch 7" }, "*", entityTypeFullName).then(b => {
console.log(b);
});
await batch.execute();
console.log("Done")
这个方法的用法很简单,就是先创建一个Batch,然后把更新加到Batch里面,最后执行就行了!
至于效率,比一个一个更新那是快多了,大家可以试一试!
结束语
大家如果有用到好的API,都记得要分享,不要藏私!相信,SharePoint会越来越好~
| 博文推荐: |
| SharePoint 2013 WebPart 管理工具分享[开源] |
| 基于SharePoint 2013的论坛解决方案[开源] |
| SharePoint 2013 学习基础系列入门教程 |
| SharePoint 2013 图文开发系列之门教程 |
| SharePoint Designer 学习系列入门教程 |
| 特:如果有Power Platform、Azure、Microsoft 365、SharePoint项目,欢迎邮件联系我,Email:linyu_s@163.com |

浙公网安备 33010602011771号