尝试使用 sp/pnp 将多个项目添加到 SP 列表,但在“createBatch()”上出现错误
我正在关注这个文档: https://pnp.github.io/pnpjs/sp/items /#添加多个项目 但我收到一个错误:
import { SPFI, spfi, SPFx } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/lists";
import "@pnp/sp/items";
import "@pnp/sp/comments"
import "@pnp/sp/site-users/web";
let sp: SPFI;
export const CreateTableItems = async (listName: string, items: IMoscow) => {
const batch = sp.web.createBatch()
};
它说“IWeb &”类型上不存在属性“createBatch”。 IInvokable
我显然遗漏了一些东西,但文档并没有说清楚。我正在使用最新的 v3 版本的 sp/pnp,并且我能够很好地提交/更新单个项目。
I'm following this documentation:
https://pnp.github.io/pnpjs/sp/items/#add-multiple-items
But I'm getting an error with:
import { SPFI, spfi, SPFx } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/lists";
import "@pnp/sp/items";
import "@pnp/sp/comments"
import "@pnp/sp/site-users/web";
let sp: SPFI;
export const CreateTableItems = async (listName: string, items: IMoscow) => {
const batch = sp.web.createBatch()
};
It's saying Property 'createBatch' does not exist on type 'IWeb & IInvokable<any>'.
I'm clearly missing something but the docs don't make it clear. I'm using the latest v3 version of sp/pnp and I am able to submit/update single items fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许你已经失去了这个进口。
导入“@pnp/sp/batching”;
https://learn.microsoft.com/es-es/sharepoint/dev/spfx/web-parts/guidance/use-sp-pnp-js-with-spfx-web-parts
Maybe you've lost this import.
import "@pnp/sp/batching";
https://learn.microsoft.com/es-es/sharepoint/dev/spfx/web-parts/guidance/use-sp-pnp-js-with-spfx-web-parts
看来 createBatch 不是 sp.web 的一部分,我们需要使用 createBatch 函数并提供列表对象作为参数。在我的场景中,我想使用批处理删除多个项目,并按如下方式实现
Ref- 高级批处理
It seems createBatch is not part of sp.web and we need to use createBatch function and provide the list object as parameter. In my scenario, I wanted to delete multiple items using batching and implemented as below
Ref- Advanced Batching