在 componentDidMount 中selectTodo,将this.props.selected. 在控制台中,我检查 selectTodo 是一个包含comments. 我正在尝试访问此数组,但出现错误:错误:
未捕获的类型错误:无法读取未定义的属性“地图”
class Details extends Component {
constructor() {
super();
this.state = {
resul: []
selectTodo:[]
};
}
componentDidMount() {
axios.get(" http://....../todos")
.then(response => {
this.setState({
resul: response.data,
selectTodo: this.props.selected
});
})
.catch(error => {
console.log('Error fetching and parsing data', Error);
}
);
}
render () {
return (
<div>
{
{
this.state.selectTodo.comments.map((obj, i) => {
return <li>{obj["comment"]}</li>
})
}
}
</div>
);
}
}
export default Details;
控制台日志
console.log(this.state.selectTodo);
return:
Object
comments: (2) [{'comment': 'sdsd'}, {'comment': 'sdsdsdsds'}]
id: 1
错误:未捕获的类型错误:无法读取未定义的属性“地图”
慕斯709654
相关分类