数据格式:(此数据写在了getInitialState方法中)

list: [{
     'id':'1',
     'title':'123',
     'time':'2017',
     'person':'cheny0815',
     'type':'type',
     'operation':'operation'
   },{
     'id':'2',
     'title':'456',
     'time':'2017',
     'person':'cheny0815',
     'type':'type',
     'operation':'operation'
   },{
     'id':'3',
     'title':'789',
     'time':'2017',
     'person':'cheny0815',
     'type':'type',
     'operation':'operation'
   }]

页面中遍历方法(此处用this.state.list便可以取到值)

<table>
    <tbody>
        <tr className="first_tr">
          <td>内容</td>
          <td>发起人</td>
          <td>类型</td>
          <td>时间</td>
          <td>操作</td>
        </tr>
        {
          this.state.list.map(function(name){
            return (
                <tr key={name.id}>
                  <td>{name.title}</td>
                  <td>{name.person}</td>
                  <td>{name.type}</td>
                  <td>{name.time}</td>
                  <td>{name.operation}</td>
               </tr>
            )
          })
        }
    </tbody>
</table>

使用map遍历时,需要给子元素添加一个key,作为唯一的标识,而且key值必须要连续,否则会报错
这里写图片描述

GitHub 加速计划 / js / json
41.72 K
6.61 K
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
960b763e 2 个月前
8c391e04 5 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐