其他分享
首页 > 其他分享> > SharePoint Online PnPjs 批量更新项目

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会越来越好~

标签:sp,pnp,PnPjs,SharePoint,list,Batch,batch,Online,import
来源: https://www.cnblogs.com/jianyus/p/15848340.html