-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_view.html
61 lines (61 loc) · 1.47 KB
/
list_view.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Text input example</title>
<script src="lib/react-0.13.3.js"></script>
<script src="lib/JSXTransformer-0.13.3.js"></script>
</head>
<body>
<script type="text/jsx">
var Button = React.createClass({
render:function(){
return (
<input type="button" onClick={this.props.action} value={this.props.value}/>
);
}
});
var ListView = React.createClass({
render:function(){
var resultRows = this.props.array.map(function(result){
return (
<li>
<span>{result}</span>
</li>
);
}, this);
return(
<ul>
{resultRows}
</ul>
);
}
});
var App = React.createClass({
getInitialState:function(){
return({
textMessage : "",
array : []
});
},
update:function(e){
this.setState({textMessage:e.target.value});
},
add:function(e){
this.state.array.push(this.state.textMessage);
this.setState({array:this.state.array});
},
render:function(){
return (
<div>
<ListView array={this.state.array}/>
<input type="text" onChange={this.update}/>
<Button value="Add" action={this.add}/>
</div>
);
}
});
React.render(<App />,document.body);
</script>
</body>
</html>