记录一下tmpl的用法

一.基本用法

1.引入 jquerytmpl 脚本

  • https://code.jquery.com/jquery-3.5.1.min.js
  • https://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js

2.写模板

<script id="myTemplate" type="text/x-jquery-tmpl">
    <tr><td>${ID}</td><td>${Name}</td></tr>
</script>

3.数据

var users = [
    { ID: 'think8848', Name: 'Joseph Chan' }, 
    { ID: 'aCloud', Name: 'Mary Cheung'}];

4.绑定模板

$('#myTemplate').tmpl(users).appendTo('#rows');

5.html

<tbody id="rows"></tbody>

二. 逻辑判断

###1. 条件语句