现在有后端提供的类似下面这种格式的数据
{
status:X,
body:
[
{year: 2017, month: [December, October, ...]}
{year: 2016, month: [December, October, ...]}
{year: 2015, month: [December, October, ...]}
...
]
}
需要在 React 中渲染成
{year}}>
{month}
{month}
{year}}>
{month}
{month}
...
我目前可以想到的是用 map,可以做到把 year 渲染出来:
this.state = {
year: data.body.map((x) => { return x.year }),
}
const dateList = this.state.year.map((item, index) => {
return (
{item}}>
xxxx
)
});
但是对应的 month 我不知道该如何才能渲染进不同的 中去了,希望高手能指点一下,十分感谢。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
已解决。
之前总想着要把 year 和 month 单独弄出来,是个误区