`

React/JS/Es6 多重/双层循环数组/Object/Map

阅读更多

1、数据源:

var module = [
  {
    "1": [
      {
        "name": "公告区",
        "todayposts": "0",
        "fid": "2"
      },
      {
        "name": "产品动态",
        "todayposts": "0",
        "fid": "58"
      },
      {
        "name": "点小融专区",
        "todayposts": "0",
        "fid": "72"
      },
      {
        "name": "点融黑帮",
        "todayposts": "0",
        "fid": "73"
      }
    ],
    "59": [
      {
        "name": "版务管理",
        "todayposts": "0",
        "fid": "60"
      },
      {
        "name": "投诉建议",
        "todayposts": "0",
        "fid": "70"
      },
      {
        "name": "问题求助",
        "todayposts": "0",
        "fid": "42"
      }
    ]
    ......
]

 

2、React多重循环

<select value={ state.form.fid } onChange={ this.setStateByKey.bind(this, 'fid') }>
  <option value="0">选择版块</option>
  {
    Object.keys(modules).map((key) => (
      modules[key].map((item) => (
        <option key={item.fid} value={item.fid}>{item.name}</option>
      ))
    ))
  }
</select>

 



有疑问或技术交流,扫描公众号一起讨论学习。

更多React在线学习访问:http://each.sinaapp.com/react/index.html

更多实例应用扫码体验:

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics