SPFx-无法从SP列表读取人员字段

我正在尝试从SharePoint中的人员字段中获取数据。我的代码始终返回8行(正确),但是在包含Person的项目上,它返回[object Obejct]。 enter image description here

export interface SPUser {
  Pracovnik: String;
}

.
.
private getListData(): void {
        this._getListData().then((response) => {
            this._renderList(response);
        });
      }

      private _renderList(items: SPUser[]): void {
        let html: string = '<table class="TFtable" border=1 width=100% style="border-collapse: collapse;">';
         html += `<th>Title</th>`;
         items.forEach((item: SPUser) => {
           if(item.Pracovnik != null) {
         html += `
            <tr> <td>${item.Pracovnik}</td> </tr>
         `};
        
        });
        html += `</table>`;
        const listContainer: Element = this.domElement.querySelector('#spGetListItems');
        listContainer.innerHTML = html;
        
      }


      private async _getListData(): Promise<SPUser[]> {
        return pnp.sp.web.lists.getByTitle("org_struktura").items.select("Pracovnik/ID").expand("Pracovnik").get().then((response) => {
          return response;
        });
      }
      
      
      
      public render(): void {
      this.domElement.innerHTML = `
      <div class="parentContainer" style="background-color: lightgrey">
      <div style="background-color: lightgrey" id="spGetListItems" />
      </div> 
      `;  
      this.getListData();    
    }

有什么想法吗?

super__1987cl 回答:SPFx-无法从SP列表读取人员字段

通过示例示例将SharePoint列表项映射到Type对象。

export interface IReactItem{ 
  Id:number,Title:string,Description:string,User:{ID:number,EMail:string},enableEdit:boolean
}

private async _getListData(): Promise<IReactItem[]> {
  return pnp.sp.web.lists.getByTitle("TestList").items.select("Id,Title,Description,User/ID,User/EMail").expand("User").get().then((response:IReactItem[]) => {
    return response;
  });
}

enter image description here

本文链接:https://www.f2er.com/3143827.html

大家都在问