React - how to map nested object values?

前端 未结 3 775
野趣味
野趣味 2020-12-30 15:37

I am just trying to map nested values inside of a state object. The data structure looks like so:

I want to map each milestone name and then all tasks insid

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-30 15:55

    You can use nested maps to map over the milestones and then the tasks array:

     render() {
      return (
        
    {Object.keys(this.state.dataGoal.milestones).map((milestone) => { return (
    {this.state.dataGoal.milestones[milestone].tasks.map((task, idx) => { return ( //whatever you wish to do with the task item ) })}
    ) })}
    ) }

提交回复
热议问题