因此,我有一組與特定團隊綁定的用戶數組,每個用戶都擁有特定的權限。如果用戶綁定到多個團隊,這些團隊的陣列太可供選擇:ReactJS如何遍歷數組並獲取另一個數組內的對象的特定屬性
[
{
"name" : "user1",
"teams": [
{"id": "123", "name": "team-1", "permissions" : 1}
]
},
{
"name" : "user2",
"teams": [
{"id": "123", "name": "team-1", "permissions" : 3}
]
},
{
"name" : "user3",
"teams": [
{"id": "456", "name": "team-2", "permissions" : 3},
{"id": "789", "name": "team-3", "permissions" : 3},
{"id": "123", "name": "team-1", "permissions" : 3},
{"id": "233", "name": "team-4", "permissions" : 3}
]
}
]
所以現在我想這樣的:
我得到了現在的球隊我看的ID( ID:123),如何映射數組,以便我可以僅顯示ID爲123的團隊的權限?
我做了以下,但沒有奏效,因爲User3的第一項是錯誤的團隊。
const MembersTable = observer(({ state }) => (
<div>
<table className="table table-hover table-responsive">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Permissions</th>
</tr>
</thead>
<tbody>
{state.accounts.map((account, i) => <MembersTableData state={state} account={account} team={account.teams} key={i}/>)}
</tbody>
</table>
</div>
))
const MembersTableData = observer(({ state, account, organization }) => (
<tr>
<td>
<span>{account.fullName}</span>
</td>
<td>{account.email}</td>
<td>
{team[0].permissions == 1 && <span>member</span>}
{team[0].permissions == 2 && <span>administrator</span>}
{team[0].permissions == 3 && <span>super admin</span>}
</td>
</tr>
))
this.state.team
在這種情況下是「123」。
我該如何解決這個問題?
謝謝,這對我的作品! :-) – Steve