現(xiàn)在有后端提供的類(lèi)似下面這種格式的數(shù)據(jù){ status:X,
body:
[
{year: 2017, month: [December, October, ...]}
{year: 2016, month: [December, October, ...]}
{year: 2015, month: [December, October, ...]}
...
]
}需要在 React 中渲染成<SubMenu key={year} title={<span>{year}</span>}>
<Menu.Item key={month}>{month}</Menu.Item>
<Menu.Item key={month}>{month}</Menu.Item>
</SubMenu>
<SubMenu key={year} title={<span>{year}</span>}>
<Menu.Item key={month}>{month}</Menu.Item>
<Menu.Item key={month}>{month}</Menu.Item>
</SubMenu>...我目前可以想到的是用 map,可以做到把 year 渲染出來(lái): this.state = { year: data.body.map((x) => { return x.year }),
} const dateList = this.state.year.map((item, index) => { return (
<SubMenu key={index} title={<span>{item}</span>}>
xxxx </SubMenu>
)
});但是對(duì)應(yīng)的 month 我不知道該如何才能渲染進(jìn)不同的 <Menu.Item></Menu.Item>中去了,希望高手能指點(diǎn)一下,十分感謝。
React 中嵌套數(shù)組數(shù)據(jù)如何渲染到前端頁(yè)面
達(dá)令說(shuō)
2018-10-19 18:15:32