簡體   English   中英

如何使用 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);
    })

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM