-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-模板引擎的使用.html
79 lines (76 loc) · 1.84 KB
/
02-模板引擎的使用.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<ul>
<li>运动馆</li>
<li>运动馆</li>
<li>运动馆</li>
<li>运动馆</li>
<li>运动馆</li>
<li>运动馆</li>
</ul>
<script id="tpl" type="text/html">
<!-- 是数组就each遍历 -->
{{each rows}}
<li></li>
{{/each}}
<!-- 不是数组直接写 -->
条数:{{total}}
<!-- {{each rows}}
for (var i = 0; i < rows.length; i++) {
rows[i]
} -->
<!-- {{each list}}
for (var i = 0; i < list.length; i++) {
list[i]
} -->
</script>
<!-- 4.0最新版 -->
<script src="public/m/lib/artTemplate/template-web.js"></script>
<script>
var obj = {
"total": 5,
"rows": [{
"id": 1,
"categoryName": "运动馆",
"isDelete": 1
}, {
"id": 2,
"categoryName": "女士馆",
"isDelete": 1
}, {
"id": 3,
"categoryName": "男士馆",
"isDelete": 1
}, {
"id": 4,
"categoryName": "帆布馆",
"isDelete": 1
}, {
"id": 5,
"categoryName": "户外管",
"isDelete": 1
}]
}
var obj2 = {
list: obj.rows
}
console.log(obj);
console.log(obj2);
// 模板引擎要求传入对象 参数必须是对象 如果是对象就没有必要包了
template('tpl', obj);
// 如果不是对象就包装在对象里面
template('tpl', {list:[1,2,3,4]});
// for (var i = 0; i < list.length; i++) {
// list[i]
// }
// for (var i = 0; i < rows.length; i++) {
// rows[i]
// }
</script>
</body>
</html>