尝试使用 sp/pnp 将多个项目添加到 SP 列表,但在“createBatch()”上出现错误

发布于 2025-01-13 10:58:07 字数 646 浏览 1 评论 0原文

我正在关注这个文档: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最好是你 2025-01-20 10:58:07

看来 createBatch 不是 sp.web 的一部分,我们需要使用 createBatch 函数并提供列表对象作为参数。在我的场景中,我想使用批处理删除多个项目,并按如下方式实现

import { SPFI, spfi, SPFx } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/lists";
import "@pnp/sp/items";
import "@pnp/sp/batching";
import "@pnp/sp/items/get-all";
import { createBatch } from "@pnp/sp/batching";
let sp: SPFI;

export const DeleteItems = async (listName: string) => {
    const list = await sp.web.lists.getByTitle(listName);
    const items = await list.items.getAll();
    const [batchedListBehavior, execute] = createBatch(list);
    list.using(batchedListBehavior);
    items.forEach((i: IItem) => {
        list.items.getById(i["ID"]).delete();
    });
    await execute();
};

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

import { SPFI, spfi, SPFx } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/lists";
import "@pnp/sp/items";
import "@pnp/sp/batching";
import "@pnp/sp/items/get-all";
import { createBatch } from "@pnp/sp/batching";
let sp: SPFI;

export const DeleteItems = async (listName: string) => {
    const list = await sp.web.lists.getByTitle(listName);
    const items = await list.items.getAll();
    const [batchedListBehavior, execute] = createBatch(list);
    list.using(batchedListBehavior);
    items.forEach((i: IItem) => {
        list.items.getById(i["ID"]).delete();
    });
    await execute();
};

Ref- Advanced Batching

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文