【发布时间】:2021-05-18 17:37:39
【问题描述】:
这是我正在迭代的数组:
[
{
"Categories": [
{
"Name": "Program",
"Description": "This is a program",
"Errors": [
{
"Name": "Program_not_found",
"Value": 1,
"Description": "There is an error in this program."
}
]
},
{
"Name": "ProgramTwo",
"Description": "This is programTwo.",
"Errors": [
{
"Name": "ProgramTwo is not found",
"Value": 1
},
{
"Name": "ProgramTwo is missing data",
"Value": 2
}
]
}
]
}
]
在另一个文件中,我正在遍历这些数据并在此处的地图下得到一个红色曲线:
{Errors.map(({Name, Value, Description}, key)
我的代码编译并正确显示了信息。如果代码正在编译,我不明白为什么 map 函数下面有一个红色的波浪线。当我将鼠标悬停在 .map 上时,它不会提供有关错误的任何信息。我希望有人能告诉我为什么会发生这种情况以及如何解决它。这是我的组件的样子:
const Categories = () => {
return (
<h1>Error Codes</h1>
<div className="error-codes">
{errorCodes.map(({Categories}, key) => (
<div key={key}>
{Categories.map(({Name, Description, Errors}, key) => (
<div key={key}>
<p>{Name}</p>
<p>{Description}</p>
{Errors.map(({Name, Value, Description}, key) => ( //Getting red squiggle under map here
<div key={key}>
<p>{Name}</p>
<p>{Value}</p>
<p>{Description}</p>
</div>
))}
</div>
))}
</div>
))}
</div>
)
}
export default Categories;
【问题讨论】:
-
也许
Errors可能为 null 或未定义(例如在初始化时),然后它将没有属性map。
标签: arrays json reactjs array.prototype.map