【发布时间】:2021-05-07 07:56:00
【问题描述】:
keylist 数组中有一个列列表,item 数组中有所有数据。
以下代码在控制台中运行良好。但是在反应中它显示了这个错误An error occurred while rendering the visualization: Error: Objects are not valid as a React child (found: Invalid Date). If you meant to render a collection of children, use an array instead.
<div>
{
data.map((item) => {
console.log("new row: ")
return (
<div className="row">
{
keylist.map(subitem => {
return(
// <p>{item[subitem]}</p>
console.log(item[subitem])
)
})
}
</div>
)
})
}
</div>
【问题讨论】:
-
将控制台日志放在return语句之前。
-
并从您的 return 语句中返回一个有效元素。这应该工作
-
@ahmed 你能给我一个有效返回元素的例子吗?
-
return ( console )有效,但我想打印该元素。return ( <p>{item[subitem]}</p>)有问题 -
我在答案中提供了解决方案。希望对您有所帮助。
标签: javascript arrays reactjs apache-superset tsx