在我的项目启动时,我收到一条错误,指出 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
或断点)。当您第一次访问该页面时,该值很可能是未定义
,因此访问该页面上的属性会导致错误。
我建议在分配给 details
之前添加一个 if(currentData)...
条件。
关于javascript - 未定义错误的属性在刷新时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59200753/