-
Notifications
You must be signed in to change notification settings - Fork 0
/
example7-BetweenComponents.html
85 lines (77 loc) · 1.87 KB
/
example7-BetweenComponents.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>example7</title>
<script src="build/react.js"></script>
<script src="build/react-dom.js"></script>
<script src="build/browser.js"></script>
<script src="build/jquery.js"></script>
<script src="build/remarkable.js"></script>
</head>
<body>
<div id="example"> </div>
<div id="example2"> </div>
<script type="text/babel">
var handleClick = function(i, props) {
console.log('You clicked: ' + props.items[i] + [i]);
}
function GroceryList(props) {
return (
<div>
{props.items.map(function(item, i) {
return (
<div onClick={handleClick.bind(this, i, props)} key={i}>编号:{i} + + {item}</div>
);
})}
</div>
);
}
ReactDOM.render(
<GroceryList items={['Apple', 'Banana', 'Cranberry']} />,
document.getElementById('example')
);
var dataList = [
'apple', 'banana', 'orange'
]
var Single = React.createClass({
handleClick: function(){
this.props.parentClick(this.props.num);
},
render: function(){
return (
<p onClick={this.handleClick}>{this.props.item}{this.props.num}</p>
)
}
});
var Comment = React.createClass({
pk:function(key){
var d = this.props.data;
// console.log(d);
var items = d.filter(function(item, i) {
return key !== i;
});
console.log(items);
// this.setState({this.props.data: items});
},
render: function(){
var self = this;
var commentNodes = this.props.data.map(function(item,key){
return (
<Single item={item} key={key} num={key} parentClick={self.pk}/>
);
});
return (
<div>
{commentNodes}
</div>
)
}
});
ReactDOM.render(
<Comment data={dataList}/>,
document.getElementById('example2')
)
</script>
</body>
</html>