-
Notifications
You must be signed in to change notification settings - Fork 4
/
8list.html
95 lines (87 loc) · 1.72 KB
/
8list.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>React 8_List</title>
<script src="JSXTransformer.js"></script>
<script src="react.min.js"></script>
<style>
table {
border-collapse:collapse;
}
td {
border:1px solid gray;
padding:5px;
}
thead {
background-color: #eee;
}
</style>
</head>
<body>
<script type="text/jsx">
/**
* @jsx React.DOM
*/
// 数据定义
var data = [
{
name:"大众",
nation:"德国"
},
{
name:"丰田",
nation:"日本"
},
{
name:"奇瑞",
nation:"中国"
}
];
// 汽车组件定义
var Car = React.createClass({
render: function () {
return (
<tr>
<td>{this.props.name}</td>
<td>{this.props.nation}</td>
</tr>
)
}
});
// 汽车列表表头
var CarListTitle = React.createClass({
render: function () {
return (
<thead>
<tr>
<td>名称</td>
<td>国别</td>
</tr>
</thead>
)
}
});
// 汽车列表组件定义
var CarList = React.createClass({
render: function () {
// cars返回是一个<Car>组件的集合
var cars = this.props.data.map(function (car) {
return <Car name={car.name} nation={car.nation} />
});
// 这里直接输出cars集合
return (
<table>
<CarListTitle />
{cars}
</table>
)
}
});
React.render(
<CarList data = {data}/>,
document.body
)
</script>
</body>
</html>