我有两个数组
this.state.race
{
“ raceName”:“总统”,
“ raceID”:100
}
this.state.candidates(例如)
{
“ canName”:“约翰”,
“ canID”:1
“ raceID”:100
},
{
“ canName”:“ David”,
“ canID”:2
“ raceID”:100
},
{
“ canName”:“ Sally”,
“ canID”:3,
“ raceID”:101
}
我想显示所有种族,并且只显示具有匹配种族ID的候选人
所以会是这样:
种族100: 1.约翰 2.大卫 第101场: {空列表}
我的代码是这样的:
render() {
return (
{this.state.racelist.map(myrace => (
{myrace.title}
<divider />
{this.state.candidatelist.map(mycand => (
{/********************************************************
how can i put a conditional statment here that checks to see if,
mycand.raceID === myrace.raceID ???? and if those match, render
mycand info
********************************************************/}
))}
))}
)
}
答案 0 :(得分:0)
list.map(item => if(condition) item else null)
list.filter(condition).map(renderItem)