Javascript 未定义错误的属性在刷新时消失
在我的项目开始时,我收到一个错误,声明TypeError:Cannotread属性'ActionType'为undefined。这只发生在我第一次打开项目时。当我刷新页面时,错误消失,不再出现Javascript 未定义错误的属性在刷新时消失,javascript,reactjs,undefined,Javascript,Reactjs,Undefined,在我的项目开始时,我收到一个错误,声明TypeError:Cannotread属性'ActionType'为undefined。这只发生在我第一次打开项目时。当我刷新页面时,错误消失,不再出现 const details = { ActionType: currentData.ActionType, RequestedByName: currentData.RequestedByName } 检查opt数组的值,特别是opt[tableMeta.rowIndex]添加console.log
const details = {
ActionType: currentData.ActionType,
RequestedByName: currentData.RequestedByName
}
检查opt数组的值,特别是opt[tableMeta.rowIndex]添加console.log或断点。第一次访问页面时,值很可能未定义,因此访问页面上的属性会导致错误
我建议添加一个ifcurrentData。。。条件,然后再指定给详细信息。可能是第一次发生时,您的数据仍然未定义,但之后它会被缓存,因此您的结果很好-请尝试使用诸如ActionType:currentData之类的三元值来缩短此过程?currentData.ActionType:[]
{
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>
)
}
}
},