【问题标题】:Microsoft Graph Toolkit - How to loop through Get component result using React and default templateMicrosoft Graph Toolkit - 如何使用 React 和默认模板循环获取组件结果
【发布时间】:2021-04-01 14:20:03
【问题描述】:

在 Get 组件中使用 default 模板,返回整个结果。使用 React Graph Toolkit 组件时,如何在创建的模板中循环遍历此结果集,并创建 f.ex。每个结果项的人员组件?

【问题讨论】:

    标签: reactjs sharepoint spfx microsoft-graph-toolkit


    【解决方案1】:

    如果您正在获取/user 资源并且结果是一个数组,那么value 模板会更合适:

    const LoadingPerson = (props: MgtTemplateProps) => {
      return <div><Spinner size={SpinnerSize.large} label="Loading members..." /></div>;
    };
    
    const MemberPerson = (props: MgtTemplateProps) => {
      const person = props.dataContext;
      return <div>
        <Person userId={person.userPrincipalName} view={PersonViewType.twolines} fetchImage={true} showPresence={true}
          personCardInteraction={PersonCardInteraction.hover} line2Property="mail"></Person>
      </div>;
    };
    
    <Get resource="/users" scopes={["User.Read.All"]}>
        <MemberPerson template="value" />
        <LoadingPerson template="loading" />
    </Get>
    

    更多参考:

    【讨论】:

    • 谢谢!我已经在使用value 模板。但是我需要在渲染之前对结果集进行排序。我怎样才能做到这一点?我被告知要使用default 模板,请参考此线程:stackoverflow.com/questions/64573688/…
    猜你喜欢
    • 2021-02-10
    • 2021-05-01
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 2011-10-09
    • 1970-01-01
    相关资源
    最近更新 更多