【问题标题】:React native with redux accessing hash使用 redux 访问哈希反应原生
【发布时间】:2019-07-26 01:55:10
【问题描述】:

我正在使用 react native 和 redux。商店返回一个简单的哈希,如下所示:

hash = { "1": {"questions": {'1': 'A', '2': '', '3': '', '4': '', '5': '', '6': 'A' } } }

问题是我无法通过这种方式访问​​值:

hash[1].questions['1'] // should return A

如果哈希是在商店(redux)之外创建的,我可以正常访问。 我怎么解决这个问题 ? 谢谢。

【问题讨论】:

  • 我认为普通对象你也做不到。试试 hash["1"].questions["1"]。它是一个对象而不是数组,你不能使用索引 a number而是一个“字符串”。
  • hash["1"].questions 不起作用:未定义不是对象

标签: react-native redux


【解决方案1】:

问题不是很清楚,你用的是redux-persist吗?如果是,问题可能是因为你存储的对象没有被 redux-persist 实例化,你可能需要使用这个组件:

https://github.com/rt2zz/redux-persist-immutable

redux-persist恢复的信息不能作为实例处理。

【讨论】:

    猜你喜欢
    • 2020-09-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-19
    • 2020-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多