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

时间:2020-01-24 15:29:48

标签: sharepoint-online spfx

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

这是提交代码:

bash-5.0# ping -c 3 google.com
PING google.com (216.58.201.110) 56(84) bytes of data.
64 bytes from prg03s02-in-f14.1e100.net (216.58.201.110): icmp_seq=1 ttl=55 time=0.726 ms
64 bytes from prg03s02-in-f14.1e100.net (216.58.201.110): icmp_seq=2 ttl=55 time=0.586 ms
64 bytes from prg03s02-in-f14.1e100.net (216.58.201.110): icmp_seq=3 ttl=55 time=0.451 ms

--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 10ms
rtt min/avg/max/mdev = 0.451/0.587/0.726/0.115 ms
bash-5.0# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         169.254.1.1     0.0.0.0         UG    0      0        0 eth0
169.254.1.1     *               255.255.255.255 UH    0      0        0 eth0
bash-5.0# traceroute google.com
traceroute to google.com (216.58.201.110), 30 hops max, 46 byte packets
 1  10-68-149-194.kubelet.kube-system.svc.kube.example.com (10.68.149.194)  0.006 ms  0.005 ms  0.004 ms

这很好。

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

以下是检索功能:

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);

以及上面的_getListItems()函数:

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));
        }

      });
    }
  }

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

1 个答案:

答案 0 :(得分:1)

首先获取项目,然后获取项目附件文件。

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

enter image description here