html
<div id="box"></div>
template.tpl
<script id="template1" type="text/html">
{{each}}
<div class="item">{{value}}</div>
{{/each}}
</script>
page.js
$("#box .item").remove() //先删除元素
var tpl = template("template1",['测试1','测试2'])
$("#box").append(tpl)
如果网络比较慢 页面资源加载过慢 就会导致重复添加
渲染后页面代码为
<div class="item">测试1</div>
<div class="item">测试2</div>
<div class="item">测试1</div>
<div class="item">测试2</div>
先删除再添加的 想不通为啥会重复叠加???我太菜了。。。
嗯,找到答案再补充。。。
目前我是通过html()解决的
var tpl = template("template1",['测试1','测试2'])
$("#box").html(tpl)