0

我有一个 SPFX webpart,它在启动时会从 SPO 列表中检索项目列表并显示它们:

const Owner = item.OwnerId;
var itemOwner = sp.web.getUserById(Owner).select("Title", "Owner/Title").expand("Owner").get().then(r => {
            console.log(r, 'r');
          }); //this successfully retrieves the title for each item, 
but how would I implement it into the repeated list below in replacement of item.OwnerId?

 return (
   <div>
       <tr>
        <td style={{ width: '80px' }}>{item.Created}</td>
        <td style={{ width: '100px' }}>{item.OwnerId}</td>
        <td style={{ width: '100px' }}>{item.FormStatus}</td>
        <td style={{ width: '15px' }}>
        <div className={styles.editIcon}><Icon iconName="Edit" id={item.Id.toString()} onClick={this._editItem} />
       </div>
      </td>
     </tr>
   </div>
  );

我想显示所有者列的标题而不是 ID。因此,我可以从 SPO 列表中检索所有者列的 ID,它将成功显示在项目列表中,但我无法理解如何扩展所有者列以显示所有者的标题。你可以在上面看到我是如何尝试的。但它显示一个错误。

我用于检索列表的数据模型和接口:


export interface IEIAItem {
....
    Owner: string;
    OwnerId: any;
....
}

export class EIAItem implements IEIAItem {
....
    public Owner: string;
    public OwnerId: any;

....   
    constructor(item: IEIAItem){
....
        this.Owner=item.Owner;
        this.OwnerId=item.OwnerId;
....
    }
}
4

1 回答 1

0

我了解所有者是您列表中的单个人员列。您可以通过列表项直接获取它:

const items = await sp.web.lists.getByTitle("LookupList").items.select("Created", "Lookup/Title", "Lookup/ID").expand("Lookup").get();

无需向用户资源发送第二个请求。上述请求将返回您指定的视图字段。

测试:

在此处输入图像描述

于 2020-12-15T01:50:30.007 回答