-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
74 lines (63 loc) · 1.68 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>miniRender</title>
</head>
<body>
<div id="box">
<h3>first:</h3>
<p>{{first}}</p>
<h3>支持三元运算</h3>
<p>{{ gt > 8 ? gt : 8 }}</p>
<h3>空值:</h3>
<p>{{empty}}</p>
<h3>过滤:</h3>
<p>{{ word | toUpperCase }}</p>
<h3>判断:</h3>
{{IF gt > lt}}
<p>gt比较大:{{gt}}</p>
{{ELSEIF lt < gt}}
<p>lt比较小:{{lt}}</p>
{{ELSE}}
<p>都不成立</p>
{{/IF}}
<h3>循环数组:</h3>
{{EACH item, index IN array}}
<p>索引:{{index}} 值:{{item}}</p>
{{/EACH}}
<h3>循环对象:</h3>
{{EACH val, key IN object}}
<p>属性名:{{key}} 属性值:{{val}}</p>
{{/EACH}}
</div>
</body>
<script src="./src/miniRender.js"></script>
<script>
var data = {
gt: 7,
lt: 6,
first: 'first',
array: [1,2,3],
object: {
key1: 'value1',
key2: 'value2'
},
word: 'aaaaa',
empty: undefined
}
// 渲染字符串模板
var str = miniRender.renderString('<div>{{word}}</div>', data)
console.log(str)
// 注册过滤器
miniRender.filter('toUpperCase', function(val){
return val.toUpperCase()
})
// 移除过滤器
// miniRender.removeFilter('toUpperCase')
// 渲染元素内部模板
miniRender.renderElement('#box', data)
</script>
</html>