定义:一个团队可以有多个用户和一个用户作为经理:
type Team {
id: ID!
title: String
manager: User @connection
users: [User] @connection(name: "TeamUsers")
}
用户类型定义为:
type User {
id: ID!
username: String
team: [Team] @connection(name: "TeamUsers")
}
使用js,我可以访问团队经理的用户名:
{teams.map((team) => {
return(
<li>{team.manager.username}</li>
)
}
问题:我无法使用以下任一方法获取团队中用户的用户名:
{teams.map((team) => {
return(
<li>{team.users.username}</li>
// or
<li>{team.users.map((user) => {user.username})}</li>
)
}
ps)我正在使用aws amplify,我正在使用以下代码获取团队:
const fetchTeams = async () => {
try {
const teamsData = await API.graphql(graphqlOperation(listTeams));
const teamsList = teamsData.data.listTeams.items;
setClients(teamsList);
} catch (error) {
console.error(`fetchTeams failed.`, error);
}
};
暂无答案!
目前还没有任何答案,快来回答吧!