简体   繁体   English

映射到 axios 响应的 _id 时未捕获类型错误:无法读取未定义的属性(读取“_id”)

[英]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.

相关问题 未捕获的类型错误:无法读取未定义的属性(读取“id”) - Uncaught TypeError: Cannot read properties of undefined (reading 'id') Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'id') - Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'id') “TypeError:无法读取未定义的属性(读取‘id’)” - "TypeError: Cannot read properties of undefined (reading 'id')" TypeError:无法读取未定义的属性(读取“_id”) - TypeError: Cannot read properties of undefined (reading '_id') 未捕获的类型错误:使用 axios 和 react-router-dom 时无法读取未定义的属性(读取“参数”) - Uncaught TypeError: Cannot read properties of undefined (reading 'params') while using axios and react-router-dom 如何解决反应项目中显示的此错误 - 未捕获(承诺)TypeError:无法读取未定义的属性(读取'id') - How to solve this error showing in react project - Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'id') JSON Object Javascript 处理。 未捕获的类型错误:无法读取未定义的属性(读取“id”) - JSON Object Javascript Handling. Uncaught TypeError: Cannot read properties of undefined (reading 'id') 未捕获的类型错误:无法读取 null 的属性(读取“_id”) - Uncaught TypeError: Cannot read properties of null (reading '_id') 未捕获的类型错误:无法读取未定义的属性(读取“0”) - Uncaught TypeError: Cannot read properties of undefined (reading '0') 未捕获的类型错误:无法读取未定义的属性(读取“0”) - Uncaught TypeError: Cannot read properties of undefined (reading '0')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM