1

我正在使用 pnp js 创建一个供我的共享点应用程序使用的列表。我尝试使用 sharepoint 框架架构对其进行配置,但我确实遇到了问题,并为此提出了问题(https://github.com/SharePoint/sp-dev-docs/issues/1253)。现在我正在尝试使用 pnp js 创建一个列表作为解决方法。我的代码看起来像这样:

pnp.sp.web.lists.ensure("listName").then((ler : ListEnsureResult) => {
                    listEnsureResults = ler;

                        if (!ler.created) {

                        resolve(ler.list);
                        return Promise.reject(LIST_EXISTS);
                        }


                        return ler.list.fields.addText("Field1");

                })

我想添加多个列,但在添加多个字段时总是出错。

4

1 回答 1

1

您可以在 SPFx 中添加多个字段,如下所示:

public addFieldsToList(listname: string): Promise<any> {
    return Promise.all([      
      pnp.sp.web.lists.getByTitle(listname).fields.addText("MyField1"),
      pnp.sp.web.lists.getByTitle(listname).fields.addText("MyField2"),
      pnp.sp.web.lists.getByTitle(listname).fields.addText("MyField3"),
      pnp.sp.web.lists.getByTitle(listname).fields.addText("MyField4"),
    ]).then((response) => {
      return response;
    }, (error: any) => {
      return error;
    }).catch((error: any) => {
      return error;
    });
}

您只需要调用此方法并传递您的列表名称。

于 2018-01-23T13:09:40.620 回答