Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TypeError:无法读取属性';然后';关于未定义---我如何解决这个问题?_Javascript_Reactjs_Redux_Es6 Promise - Fatal编程技术网

Javascript TypeError:无法读取属性';然后';关于未定义---我如何解决这个问题?

Javascript TypeError:无法读取属性';然后';关于未定义---我如何解决这个问题?,javascript,reactjs,redux,es6-promise,Javascript,Reactjs,Redux,Es6 Promise,我不知道为什么我的函数会给我这个错误。在返回值的函数中,我确保在所有级别上都有一个return语句。关于为什么会发生这种错误,我能有第二种意见吗?服务完美地返回了数据,但是前端没有看到我的操作返回的数据 我尝试了其他同名的解决方案,所以希望这不是重复的解决方案 前端: componentDidMount() { const { item } = this.props; this.props.getDetails(Number) .then((res)

我不知道为什么我的函数会给我这个错误。在返回值的函数中,我确保在所有级别上都有一个return语句。关于为什么会发生这种错误,我能有第二种意见吗?服务完美地返回了数据,但是前端没有看到我的操作返回的数据

我尝试了其他同名的解决方案,所以希望这不是重复的解决方案

前端:

componentDidMount() {       
    const { item } = this.props;
    this.props.getDetails(Number)
        .then((res) => {               
            this.setState({
                data: res.response.response.Results
            })
        });  
}
映射:

function mapDispatchToProps(dispatch) {
    return {
        getDetails(Number) {
            dispatch(getActions.getDetails(Number));
        }
    };
}
函数检索:

function getDetails(Number) { 
   return (dispatch) => {
       dispatch({ type: policyConstants.ITEM_GETDETAIL_REQUEST });
    return Service.getDetails(Number)
        .then(
            response => {                   
                dispatch({ type: Constants.ITEM_GETDETAIL_SUCCESS });
                var pDetails = response.response.Results;
                return { pDetails };
            },
            error => {
                dispatch({ type: policyConstants.POLICY_GETDETAIL_FAILURE, error});                  
            }             
        );
    }
 }

您的
组件中的
this.props.getDetails(Number)
被计算为
未定义的
,因为
mapDispatchToProps中的
getDetails
不返回任何内容

像这样改变:

function mapDispatchToProps(dispatch) {
    return {
        getDetails(Number) {
            return dispatch(getActions.getDetails(Number));
        }
    };
}

哪一行代码引发了该错误?@MattU。然后,在ComponentDidMount中的那一行,在映射函数中,您将getActions函数错误地称为“detActions.getDetails”。由
mapDispatchToProps()返回的对象的
getDetails
方法不
返回任何内容。上一个代码段中的
getDetails
函数确实返回了一个箭头函数,
服务.getDetails
从未被调用。