【问题标题】:How to use @pnp/sp to query a person column in an SP list to get the name如何使用@pnp/sp查询SP列表中的person列获取姓名
【发布时间】:2021-01-30 19:50:16
【问题描述】:

我有一个 Web 部件,它需要检索人员列(人员选择器)的 Name 属性,以便我可以使用它填充状态并随后填充一个字段。这是查询项目的函数:

private _jeChange = (ev: React.FormEvent<HTMLDivElement>, option?: IDropdownOption, index?: number) => {
    this.setState({ 
      SelectedJE: option.text,
    
    }, () => { 
      const selJE = this.state.SelectedJE;
    
    if (selJE && selJE.length > 0) {
      
      let _item = this.state.MyListItems.find((item) => {
        return item.JobRef == selJE;
      });
      this.setState({
 
        JEDeptContact: _item.DeptContactId,

   }, () => {
     sp.web.lists.getByTitle("MyList").items.getById(_item.Id).select("DeptContact", "Lookup/Name", "Lookup/ID").expand("Lookup").get().then((item: any[]) => {
          console.log(item);
        });
      
        });
      }
    });
  }

_item.DeptContactId 成功地在 person 列中使用用户的 Id 填充状态,但我想要名称而不是 Id,如何将 Id 解析为名称?我需要使用扩展来获取名称吗?如果有怎么办? 我读过这个,但我不知道在哪里使用扩展: https://pnp.github.io/pnpjs/sp/items/

【问题讨论】:

    标签: spfx


    【解决方案1】:

    找到了:

    if(_item.DeptContactId){
      sp.web.getUserById(_item.DeptContactId).select("Title", "DeptContact/Title").expand("DeptContact").get().then(r => {
          this.setState({
             JEDeptContact: r.Title,
          });
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-27
      • 2019-04-25
      • 2014-02-16
      • 1970-01-01
      • 2020-02-22
      • 1970-01-01
      相关资源
      最近更新 更多