-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patha7react案例测试.html
49 lines (47 loc) · 1.35 KB
/
a7react案例测试.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.active {display:none}
</style>
<script src="./build/react.js"></script>
<script src="./build/react-dom.js"></script>
<script src="./build/browser.min.js"></script>
</head>
<body>
<div id="example"></div>
<div id="example1"></div>
<div id="example2"></div>
<script type="text/babel">
var Component=React.createClass({
render:function() {
return (
<ul>
{
React.Children.map(this.props.children,function(child) {
return <li>{child}</li>
})
}
</ul>
)
}
})
ReactDOM.render(
<Component>
<p>Hello world!</p>
<p>Hello Universe!</p>
</Component>,
document.getElementById("example")
)
</script>
<!-- React遍历子节点的map方法和原生的好像有点不一样:
原生js的map方法为:var arr1=Array.map(function(item,index,arr) {})
其中arr参数是指原数组,因此,可以通过遍历改变原数组的每一项,还可以在内部return,每一次 return 的内容是新数组arr1的每一项;而forEach方法遍历则不论如何新数组为未定义!
React遍历子节点的方法是:
React.Children.map(this.props.children,function(child) {...})
this.props.children是实例中的子节点集合,参数 child是实例中子节点的每一项
-->
</body>
</html>