2017-11-17 12 views
1

私はimmutableJS、React/Reduxを使用しており、このマップを持っており、actionsの値を取得する必要があるので、 - >allRetrospectivesMap->id->current_stage - >actions不変JS - ネストされたマップ内の値を取得

enter image description here

、私はこのコードを持っており、それは動作しますが、それは、スーパー醜いそれを行うには良い方法はありますか?

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 
    }) 

ありがとうございます! :)

答えて

2

これは、変更不可能な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を取得することができますどのようにそれhere

+0

についての詳細を読みますか?それで私は '.map'を別の方法で使っているのですか? –

+0

あなたのデータ/状態の 'id'部分はありますか? –

+1

ああ、私はちょうどこれをしました:const id = Object.keys(retrospectives)[0] const actions = retrospectives.getIn([id、 'current_stage'、 'actions']);それは働いた! D –

関連する問題