如何使用 spfx 检索 SharePoint 列表项附件?

How can I retrieve a SharePoint list items attachments using spfx?

我已经设法弄清楚如何将多个附件提交到共享点列表项。 我现在需要检索项目并以提交的相同表单显示这些项目。

提交代码如下:

private _onSubmit() {
    this.setState({
      FormStatus: 'Submitted',
      SubmittedLblVis: true,

    }, () => {

      pnp.sp.web.lists.getByTitle("My List").items.add({

        State: this.state.State,
        State1: this.state.State1,

      }).then((iar: ItemAddResult) => {
        var attachments: AttachmentFileInfo[] = [];

        attachments.push({
          name: this.state.FileUpload[0].name,
          content: this.state.FileUpload[0]

        });

        attachments.push({
          name: this.state.FileUpload2[0].name,
          content: this.state.FileUpload2[0]
        });

        attachments.push({
          name: this.state.FileUpload3[0].name,
          content: this.state.FileUpload3[0]
        });

    iar.item.attachmentFiles.addMultiple(attachments);

效果很好。

我有一个表单按钮,允许用户阅读项目并填充表单中的所有字段。这很好用。但它不适用于附件。首先是我不知道附件栏叫什么!

检索函数如下:

private _editItem = (ev: React.MouseEvent<HTMLElement>) => {
    const sid = Number(ev.currentTarget.id);
    let _item = this.state.Items.filter((item) => { return item.Id === sid; });
    if (_item && _item.length > 0) {
      this._getListItems();
      this.setState({
        State etc...with a few examples

        FormStatus: _item[0].FormStatus, 

        showModal: true

        //The below callback function 
      }, () => {

        if (_item[0].PanelMember) {
          this.PanelMemberGetPeoplePicker(Number(_item[0].PanelMemberId));
        }

      });
    }
  }

以及上面的 _getListItems() 函数:

 public _getListItems() {
    sp.web.lists.getByTitle("MyList").items.get().then((items: any[]) => {
      let returnedItems: MyDataModel[] = items.map((item) => { return new MyDataModel(item); });

      this.setState({ Items: returnedItems });
    });
  }

我知道无论附件列是什么,我都必须更新 MyDataModel 接口,但附件列是什么?我将如何在上面实现它以检索所有 3 个附加文档?

先获取物品,再获取物品附件。

let item=sp.web.lists.getByTitle("TestList").items.getById(13);
    item.attachmentFiles.get().then((files)=>{
      console.log(files);
    })