-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathstu.html
139 lines (115 loc) · 3.75 KB
/
stu.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="node_modules/react/dist/react.js"></script>
<script src="node_modules/react-dom/dist/react-dom.js"></script>
<link rel="stylesheet" href="css/bootstrap.css">
</head>
<!--jsx-->
<body>
<div id="root">
</div>
<script src="node_modules/babel-standalone/babel.js"></script>
<script type="text/babel">
var stuInfo = [
{name: "张三", sex: "男", age: 20, id: 1},
{name: "张四", sex: "男", age: 21, id: 2},
{name: "张五", sex: "女", age: 22, id: 3},
{name: "张六", sex: "女", age: 20, id: 4},
{name: "张七", sex: "男", age: 19, id: 5}
];
class Select extends React.Component {
constructor() {
super();
}
render() {
//this.props.changeSex
return (
<select className="form-control" onChange={(e)=>{this.props.changeSex(e.target.value)}}>
<option value="0">全部</option>
<option value="1">男</option>
<option value="2">女</option>
</select>
)
}
}
class Search extends React.Component {
constructor() {
super();
}
render() {
return (
<div className="input-group" style={{marginTop: "10px"}}>
<span className="input-group-addon">搜索</span>
<input type="text" className="form-control" placeholder="Username"/>
</div>
)
}
}
class Table extends React.Component {
constructor() {
super();
}
render() {
return (
<table className="table table-bordered" style={{marginTop:"10px"}}>
<tbody>
{
this.props.stuInfo.map(function(a,b){
return <tr key={b}>
<td>{a.name}</td>
<td>{a.sex}</td>
<td>{a.age}</td>
<td>删除</td>
</tr>
})
}
</tbody>
</table>
)
}
}
class Main extends React.Component {
constructor(props) {
super(props);
this.state={stuInfo:this.props.stuInfo};
this.stuInfo=this.props.stuInfo;
}
changeSex(id){
var map={1:"男",2:"女"};
this.state={stuInfo:this.stuInfo};
if(id==0){
this.setState({stuInfo:this.stuInfo})
}else {
var arr=this.state.stuInfo.filter(function (a) {
if (map[id] == a.sex) {
return a;
}
})
this.setState({stuInfo:arr})
}
}
render() {
return (
<div>
<h3>{this.props.title}</h3>
<Select changeSex={this.changeSex.bind(this)}/>
<Search/>
<Table stuInfo={this.state.stuInfo}/>
</div>
)
}
}
/*
* 单向数据流
*
* */
ReactDOM.render(<Main title="学生花名册" stuInfo={stuInfo}/>,document.querySelector("#root"))
</script>
</body>
</html>