对于Reactjs来说还是新手,我认为我已尽力而为,但仍无法解决此错误“for (i = 0; i < col; i++){
sumC = 0;
for (j = 0; j < row; j++)
{
sumC += matrix[j][i];
if(sumC>1.5){
sumC=0;
}
}
}
”
请帮助下面是我的代码。
TypeError: Cannot read property 'id' of undefined
错误完整堆栈跟踪:
这是我试图循环的烧瓶中的数据。试图将每个对象转换为数组,然后遍历数组。我也试过console.log(lol),我得到的数据如下图所示
if(this.props.controller === 'location'){
eventData = Object.keys(this.props.heda).map( evKey => {
return Object.keys(evKey).map( post => {
return [...Array(this.props.heda[evKey][post])].map( lol => {
return <Event key= {lol['id']}
descriptions = {lol['description']}
headings = {lol['title']}
id = {lol['id']}
clicked = { ()=> this.viewSelectedEvent(lol['id']) }/>;
}) ;
});
});
}
答案 0 :(得分:1)
使用[...Array(this.props.heda[evKey][post])]
创建一个数组,其中第一个元素是数组this.props.heda[evKey][post])
。
也许您想说[...this.props.heda[evKey][post]]
来创建数组的克隆?
答案 1 :(得分:0)
因为他无法在this.props.heda[evKey][post]
对象中找到id。所以首先你应该控制你的this.props.heda[evKey][post]
对象,之后我认为你会得到你的实际问题。
答案 2 :(得分:0)
请尝试以下代码段:
this.props.heda.map((evVal, evKey) => {
return evVal.map((postVal, postKey) => {
...
}
}
现在this.props.heda [evKey] [postKey]会给你预期的对象。