使用 SharePoint spfx、React 和 Get 组件与模板的 Graph Toolkit 工作示例

2023-12-14

我正在尝试在我的 SharePoint spfx Web 部件解决方案中使用 Microsoft Graph Toolkit,更具体地说是 React 版本 (@microsoft/mgt-react)。

我已成功导入包,并正确呈现控件。

不过,我现在尝试根据控件的结果来渲染控件。像这样的东西:

const MyPerson = (props: MgtTemplateProps) => {
      const { person } = props.dataContext;
      return <Person userId={person.userPrincipalName}></Person>;
    }

这是控制:

      <Get resource={`/groups/${this.props.groupid}/members`}>
        <MyPerson template="value" />
      </Get>

什么也没有渲染出来。 有人可以帮我解决这个问题吗?

Thanks!

更新的工作示例:

  public render(): React.ReactElement<IMemberListProps> {

const LoadingPerson = (props: MgtTemplateProps) => {
      return <div><Spinner size={SpinnerSize.large} label="Loading members..." /></div>;
    };

const MemberPerson = (props: MgtTemplateProps) => {
      const person = props.dataContext;
        return <div className={styles.memberRow}>
          <Person userId={person.userPrincipalName} view={PersonViewType.twolines} fetchImage={true} showPresence={true}
            personCardInteraction={PersonCardInteraction.hover} line2Property="mail"></Person></div>;
    };

    return (
      <div>
        <Get resource={`/groups/${this.props.groupId.toString()}/members/microsoft.graph.user/?$count=true&$orderby=displayname`} >
          <MemberPerson template="value" />
          <LoadingPerson template="loading" />
        </Get>
      </div>
    );
}

The props.dataContext没有 person 属性,但它是 person 对象本身,请尝试更改您的MyPerson定义为:

const MyPerson = (props: MgtTemplateProps) => {
  const person = props.dataContext;
  return <Person userId={person.userPrincipalName}></Person>;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 SharePoint spfx、React 和 Get 组件与模板的 Graph Toolkit 工作示例 的相关文章

随机推荐