[英]while mapping into _id of axios response Uncaught TypeError: Cannot read properties of undefined (reading '_id')
Problem with map function after axios fetch. axios 提取后 map function 出现问题。 while mapping into _id of axios response Uncaught TypeError: Cannot read properties of undefined (reading '_id')
映射到 axios 响应的 _id 时未捕获类型错误:无法读取未定义的属性(读取“_id”)
state = {
options: []
}
deleteOption = (optiontodelete) => {
Axios.delete(`http://127.0.0.1:3000/options/${optiontodelete}`, { headers: AuthHeader() })
.then(res => {if(res.status === 200)
this.notifyMessage()
}).then(
this.setState({
options: this.state.options.map((item) =>{
optiontodelete !== item._id
})
})
).catch(err => console.log(err.response.data))
console.log(optiontodelete)
}```
This is the Error I got:
Uncaught TypeError: Cannot read properties of undefined (reading '_id')
//Function deleteOption is called with the argument of id (eg: 62e7563624811d383e390d1b)
What's wrong here ??
Maybe item is undefind?也许项目未定义?
console.log(item); // undefind
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.