如何在react js中获取TC id值并使用map函数
这是我的代码 json
[
{
"Results": {
"TC": [
{
"id": 1
},
{
"id": 2
},
{
"id": 3
}
]
}
}
]
这是我的反应代码:
import PostData from './result_log.json';
{PostData.map((PostDetail, index) => {
return <h1>{PostDetail.Results.TC.length}</h1>
})}
以下是如何在 json 代码中为数组中的h1
每个 id创建balise 标签TC
。
import PostData from './result_log.json';
const getAllIds = () => {
const idsArray = PostData.map(item => {
return item.Results.TC.map(it => <h1>{it.id}</h1>)
}.reduce((acc, curr) => [...acc, ...curr], [])
return idsArray
}
getAllIds()
我已经展平了第一个地图结果,因此您只有一个包含 json 代码的每个 id 键值的数组。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句