简体   繁体   English

将处于 redux 状态的对象存储为值

[英]Store an object in redux state as value

Let's say I have an object of key-value pair as following:假设我有一个键值对对象,如下所示:

Obj1 as: Obj1 为:

    { 
        'a' : ["1", "2", "3"...],
        'b' : ["6", "3", "1",...],
         ...
         ...
    }

Obj2 as : Obj2 为:

    { 
        'a' : "Football",
        'b' : "Volleyball",
         ...
         ...
    }

The key-value pairs of the obj1 and obj2 are returned from the api, and have no control over it. obj1 和 obj2 的键值对是从 api 返回的,无法控制。

I want to store it in these both object in state as : sportsCode: obj2, teamPlayers: obj1.我想将它以状态存储在这两个对象中:sportsCode:obj2,teamPlayers:obj1。

When I set it in the state with action, the state is updated correctly, but not able to retrieve with reducer, it says the value is undefined.当我将它设置为带有操作的状态时,状态会正确更新,但无法使用减速器检索,它表示该值未定义。

Found the solution to the problem.找到了问题的解决方案。 I was setting the state correctly, but not retriving properly in mapStateToProps.我正确设置了状态,但没有在 mapStateToProps 中正确检索。 Installing the chrome plugin ReduxDevTools helped in figuring it out quickly.安装 chrome 插件ReduxDevTools有助于快速解决这个问题。

thanks for the efforts.感谢您的努力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM