如何从SPFx web部件迭代Graph数据



很抱歉问了这个愚蠢的问题!

在下面的代码中,我得到了M365组的所有成员,它们显示在console.log中。

然而,我不知道如何迭代返回的JSON。

谢谢P

const theADUsers: any = await client.api(`/groups/${GUID}/members/microsoft.graph.user`)
.header('ConsistencyLevel', 'eventual')
//.search('displayName:P')
.select('displayName,id,mail,surname')
//.orderby('displayName')
.get();
console.log('theADUsers...');
console.log(theADUsers);

{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(displayName,id,mail,surname)",
"value": [
{
"displayName": "Doe, John",
"id": "GUID",
"mail": "John.Doe@somewhere.com",
"surname": "Doe"
},
{
"displayName": "Doe, John",
"id": "GUID",
"mail": "John.Doe2@somewhere.com",
"surname": "Doe"
},
{
"displayName": "Doe, John",
"id": "GUID",
"mail": "John.Doe3@somewhere.com",
"surname": "Doe"
},

您可以执行以下操作:

theADUsers.value.forEach(user => console.log(user));

结果应该已经被解析,您不需要JSON解析。如需参考,请查看此处:https://learn.microsoft.com/en-us/sharepoint/dev/spfx/use-msgraph

您可以解析json。下面是一个例子https://www.w3schools.com/js/js_json_parse.asp.

最新更新