属性 的未定义错误在刷新时消失
Property of undefined error goes away on refresh
在我的项目开始时,我收到一条错误消息,指出 TypeError: Cannot read property 'ActionType' of undefined
这仅在我第一次打开该项目时发生。当我刷新页面时,错误消失并且不会再出现。
const details = {
ActionType: currentData.ActionType,
RequestedByName: currentData.RequestedByName
}
{
name: "",
label: "",
options: {
filter: false,
sort: false,
customBodyRender: (value, tableMeta) => {
const currentData= opt [
tableMeta.rowIndex
];
const details = {
ActionType: currentData.ActionType,
RequestedByName: currentData.RequestedByName
}
return (
currentData.ActionTypeID === 0 || currentData.ActionCompletedByID > 0 ? null :
<Icon>
<Modal
details = {details}>
</Modal>
</Icon>
)
}
}
},
检查 opt
数组的值,特别是 opt[tableMeta.rowIndex]
(添加 console.log
或断点)。您第一次访问该页面时,该值可能是 undefined
,因此访问该页面上的 属性 会导致错误。
我建议在分配给 details
之前添加一个 if(currentData)...
条件。
它可能是第一次发生,你的数据仍然未定义,但之后它被缓存,所以你的结果很好 - 尝试使用三元来短路它,例如 ActionType: currentData ? currentData.ActionType : []
在我的项目开始时,我收到一条错误消息,指出 TypeError: Cannot read property 'ActionType' of undefined
这仅在我第一次打开该项目时发生。当我刷新页面时,错误消失并且不会再出现。
const details = {
ActionType: currentData.ActionType,
RequestedByName: currentData.RequestedByName
}
{
name: "",
label: "",
options: {
filter: false,
sort: false,
customBodyRender: (value, tableMeta) => {
const currentData= opt [
tableMeta.rowIndex
];
const details = {
ActionType: currentData.ActionType,
RequestedByName: currentData.RequestedByName
}
return (
currentData.ActionTypeID === 0 || currentData.ActionCompletedByID > 0 ? null :
<Icon>
<Modal
details = {details}>
</Modal>
</Icon>
)
}
}
},
检查 opt
数组的值,特别是 opt[tableMeta.rowIndex]
(添加 console.log
或断点)。您第一次访问该页面时,该值可能是 undefined
,因此访问该页面上的 属性 会导致错误。
我建议在分配给 details
之前添加一个 if(currentData)...
条件。
它可能是第一次发生,你的数据仍然未定义,但之后它被缓存,所以你的结果很好 - 尝试使用三元来短路它,例如 ActionType: currentData ? currentData.ActionType : []