您的位置:首页 > Web前端 > JavaScript

js template 和 Mustache。Mustache额使用

2016-03-14 09:15 465 查看
实例代码:

<table id="contentTable" class="table table-striped table-bordered table-condensed">
<thead><tr><th>序号</th><th>优化时间</th><th>优化前总能耗</th><th>优化后总能耗</th><th>优化后效果评估</th><th>附件</th></thead>
<tbody id="tableList"></tbody>
</table>

<script type="text/template" id="tableListTpl">
{{#list}}
<tr>
<td>{{id}}</td>
<td>{{yhTime}}</td>
<td>{{yhqEnergy}}</td>
<td>{{yhhEnergy}}</td>
<td>{{yhqResult}}</td>
<td>{{appendix}}</td>
</tr>
{{/list}}
</script>

var param = $("#searchForm").serialize();

// 异步请求
$.get(ctxStatic + "/modules/easysite/xypjGrid.json", param, function(result){
// 数据
var tpl = $("#tableListTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g, "");
$("#tableList").html(Mustache.render(tpl, result));

// 分页
$(".pagination").html(result.page);
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: