因为近期项目需要, 所以使用了art-template模板,初步认识了一下
1) 循环
<div data-div="htmlOneTwo"></div>
<script id="htmlOneTwo" type="text/html">
// list 是原始数据 type:array
// value 是 item 即 array 中的每一项的值
// i 是 index 即 array 的下标
{{each list value i}}
<div class="ups_gailan_name">
<div class="ups_gailan_name_name">{{value.name}}</div>
<div class="ups_gailan_name_val">
<input type="text" value="{{value.value}}" readonly="false" data-name={{value.dataName}}>
</div>
</div>
{{/each}}
</script>
// template
function html_template (html_div,html_array) {
var html = template(html_div, html_array);
$('[data-div='+html_div+']')[0].innerHTML = html;
}
// 调用
html_template("htmlOneTwo",formData);
2) 条件
<div data-div="htmlEdit"></div>
<script id="htmlEdit" type="text/html">
{{if appFlag === 2}}
<button class="aui-btn aui-btn-info aui-btn-block" onclick="editAndSave({{index}})">{{title}}</button>
{{/if}}
</script>
3) table
{{if value.table.tbody.length !== 0}}
<div class="status-box">
<div class="status-box-scrol">
<table class="table" style="width:100%">
<thead>
<tr>
<th>{{value.table.th.thOne}}</th>
<th>{{value.table.th.thTwo}}</th>
</tr>
</thead>
<tbody>
{{each value.table.tbody valueOne ii}}
<tr>
<td>{{valueOne.name}}</td>
<td>{{valueOne.mobile}}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</div>
{{else}}
<div class="ups_gailan_name">
<div class="ups_gailan_name_name">{{title}}</div>
<div class="ups_gailan_name_val"></div>
</div>
{{/if}}