【发布时间】:2021-05-05 04:10:25
【问题描述】:
我试图让数组的对象键显示为表的标题,但在反应中使用映射失败。 通过使用 console.log,我能够看到它返回正确的值,它在 HTML 上返回空白。
这是我的代码
<tr>
{fileList.forEach((titleList) => {
const title = [];
title.push(Object.keys(titleList))
// console.log(title)
title.map((item, key) => {
// console.log(item)
return <th key={key} scope="col">{item}</th>
})
})
}
</tr>
json 数据来自这里:https://jsonplaceholder.typicode.com/posts/1/comments 如果您愿意检查,这是我的完整项目代码:https://codesandbox.io/s/dry-wave-gu0ns?file=/src/listPage/ListPage.js
谢谢!
【问题讨论】:
标签: reactjs