Javascript Immutable JS-在嵌套映射中获取值

Javascript Immutable JS-在嵌套映射中获取值,javascript,reactjs,dictionary,redux,immutable.js,Javascript,Reactjs,Dictionary,Redux,Immutable.js,我使用的是immutableJS、React/Redux,我有这个映射,我需要获取操作的值,所以它就像->所有回顾映射->id->当前阶段->操作 我有这个代码,它可以工作,但它非常丑陋,有没有更好的方法 class UserActionItems extends Component { render() { const { retrospectives } = this.props const actions = flatten(

我使用的是immutableJS、React/Redux,我有这个映射,我需要获取
操作的值,所以它就像->
所有回顾映射
->
id
->
当前阶段
->
操作

我有这个代码,它可以工作,但它非常丑陋,有没有更好的方法

    class UserActionItems extends Component {
      render() {
        const { retrospectives } = this.props
        const actions = flatten(
          Object.keys(immutableHelpers.toJS(retrospectives))
          .map(key => retrospectives.get(key))
          .map(retro => immutableHelpers.toJS(retro.getIn(['current_stage', 'actions'])))
        ).value()

    return (
       <div> 
          <ActionsList
          actions={actions[0]}
          users={[]}
          />
       </div>
    )
  }
}

    const mapStateToProps = ({ allRetrospectivesMap }) => ({
      retrospectives: allRetrospectivesMap
    })
class UserActionItems扩展组件{
render(){
const{retrospectives}=this.props
常量动作=展平(
key(immutableHelpers.toJS(回顾))
.map(key=>retrospectives.get(key))
.map(retro=>immutableHelpers.toJS(retro.getIn(['current_stage','actions']))
).value()
返回(
)
}
}
const-mapStateToProps=({allRetrospectivesMap})=>({
回顾:所有回顾地图
})

谢谢!!!:)

您可以使用来自immutable js的
getIn()
方法来实现这一点

const id = getId() // you've id from somewhere
const actions= state.getIn(['allRetrospectivesMap', id, 'current_stage', 'actions']); // Note: state is your immutable data.

了解更多信息

如何获取id?这就是为什么我要使用
.map
还有其他方法吗?
id
是你的数据/状态的一部分吗?哦,我刚刚这么做了:const id=Object.keys(retrospectives)[0]const actions=retrospectives.getIn([id,'current_stage',actions');成功了!非常感谢:DOh,抱歉:(它不工作,它是localStorage.clear(),它停止工作xD哈哈。所以我只需要操作的第一个id,这就是为什么我尝试这个const id=Object.keys(retrospectives)[0]const actions=retrospectives.getIn([id,'current_stage',actions'))而
retrospectives
我将它作为道具传递:const-mapStateToProps=({allRetrospectivesMap})=>({retrospectives:allRetrospectivesMap})对不起,我是redux的新手,你知道怎么了吗?