summaryrefslogtreecommitdiffstats
path: root/posts/demo/execution-1.md
blob: 6be175b89b860137da07210472b4cf3c9d011a8b (plain)
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
<!--_PAGEDATA
{
    "title": "Handlebars 执行渲染",
    "github":"nimojs/handlebarsjs.org",
    "githubissuesid": 1,
    "createData": "2015-04-10",
    "keywords": "",
    "description": "轻逻辑语义化的模板引擎",
    "_template": "demo"
}
_PAGEDATA-->


<script id="entry-template" type="text/x-handlebars-template" class="show">
<!-- 模板 -->
<div class="entry">
    <h1>{{title}}</h1>
    <div class="body">
      {{body}}
    </div>
</div>
</script>

<script class="show">
// 编译模板
var source   = $("#entry-template").html();
var template = Handlebars.compile(source);
</script>

<script class="show">
// 数据
var data = {
    title: "My New Post",
    body: "This is my first post!"
}
// 渲染
$(function () {
	var html = template(data);
	$("#result,#dom").html(html);
})
</script>

<style>
#expandingPre{
    height: 200px;
}
</style>