无法读取属性“ hasOwnProperty”

时间:2019-01-09 09:06:23

标签: react-admin

更新后,如果状态码为422,则我收到一条通知,并显示以下消息:无法读取未定义的属性“ hasOwnProperty”

    TypeError: Cannot read property 'hasOwnProperty' of undefined
    at validateResponseFormat (http://localhost:4100/static/js/0.chunk.js:147058:17)
    at http://localhost:4100/static/js/0.chunk.js:147133:43
    at step (http://localhost:4100/static/js/0.chunk.js:147018:19)
    at Object.next (http://localhost:4100/static/js/0.chunk.js:146948:14)
    at next (http://localhost:4100/static/js/0.chunk.js:227925:27)
    at currCb (http://localhost:4100/static/js/0.chunk.js:228012:7)

我的api正在发送此响应:


    {
        "error": {
            "details": [{
                    "status": "week",
                    "message": "",
                    "target": "ModelState"
                }
            ],
            "innerError": null,
            "status": "422",
            "message": "Invalid model",
            "target": "ModelState"
        }
    }

1 个答案:

答案 0 :(得分:0)

我在几分钟前遇到此错误,却找不到答案。可能与dataProvider.js有关。

对于我来说,我解决了将type情况(GET_LIST,GET_ONE,UPDATE等)编辑到交换机中的问题。我将数据映射到type,并指定了要从中接收数据的resource。最好看下面的代码:

// dataProvider.js

...

switch(type){
    case GET_ONE:{
        if (resource === 'users'){
            return {
                data: {
                    id: json.id,
                    email: json.email,
                    isAdmin: json.isAdmin,
                    password: json.password
                }
            }
        }

...

}

作为免责声明,我是React-Admin和React的新手。但是我希望这个答案对发现这个问题的人有所帮助。

相关问题