码迷,mamicode.com
首页 > Web开发 > 详细

react.js 渲染一个列表的实例

时间:2017-09-19 15:07:19      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:渲染   reac   user   nbsp   one   实例   dex   head   map   

import React,{Component} from ‘react‘;
import ReactDOM from ‘react-dom‘;

let users=[
    {id:1,name:‘老王1‘,age:31},
    {id:2,name:‘老王2‘,age:32},
    {id:3,name:‘老王3‘,age:33}
]
class User extends Component{
    render(){
        return(
            <tr>
                <td>{this.props.item.id}</td>
                <td>{this.props.item.name}</td>
                <td>{this.props.item.age}</td>
            </tr>
        )
    }
}
//在一个组件中,状态越少越好
class UserList extends Component{
    render(){
        return(
            <table>
                <thead>
                <tr>
                    <th>ID</th>
                    <th>名字</th>
                    <th>年龄</th>
                </tr>
                </thead>
                <tbody>
                {
                    this.props.user.map((item,index)=>{
                    return (
                        <User item={item} key={index}></User>
                    )
                })
                }
                </tbody>
            </table>
        )
    }
}
ReactDOM.render(<UserList user={users}></UserList>,document.querySelector("#root"));

 

react.js 渲染一个列表的实例

标签:渲染   reac   user   nbsp   one   实例   dex   head   map   

原文地址:http://www.cnblogs.com/null11/p/7551195.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!