Juicer用法
1 | // juicer引入 |
自定义模板语法边界符1
2
3
4
5
6
7
8
9
10juicer.set({
'tag::operationOpen': '{@',
'tag::operationClose': '}',
'tag::interpolateOpen': '${',
'tag::interpolateClose': '}',
'tag::noneencodeOpen': '$${',
'tag::noneencodeClose': '}',
'tag::commentOpen': '{#',
'tag::commentClose': '}'
});
默认参数配置:1
2
3
4
5
6
7
8
9
10
11
12
13
14{
cache: true [false],
strip: true [false],
errorhandling: true [false],
detection: true [false]
}
修改默认配置:
// 单个修改
juicer.set('strip',false);
// 批量参数设置
juicer.set({
'strip': false,
'cache': false
})
1.$变量
1 | var json = { |
2. 内联辅助函数
1 | 即{@helper} ... {@/helper} |
3. 循环遍历
1 | 即{@each}...{@/each} |
4. 判断
1 | 即{@if}...{@else if}...{@else}...{@/if} |
5. 注释
1 | {# 注释内容} |
6. 辅助循环
1 | 即{@each i in range(m,n)} |
7. 子模版嵌套
可以在script标签中写入id1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21即{@include tpl,data}
// HTML代码
<script type="text/juicer" id="subTpl">
Im sub content, ${name},
</script>
// JavaScript代码
var tpl = 'Hi, {@include "#subTpl", subData}, End.';
juicer(tpl, {
subData: {
name: 'juicer'
}
});
// 输出 Hi, Im sub content, juicer, End
// 或者通过数据引入子模板,下述代码也将会有相同的渲染结果:
var tpl = "Hi, {@include subTpl, subData}, End.";
juicer(tpl, {
subTpl: "Im sub content, ${name}",
subData: {
name: 'juicer'
}
});
参考文章:
Juicer中文文档
如有错误,烦请指正,谢谢!