1、template.js模板引擎
2、使用
a、不循环
模板:
调用
if (res.code == 200) { var _data = res; var html = template('card_pay_tpl', _data); $('元素').html(html); } else { alert("出问题啦"); }
b、循环
模板:
调用:
if (res.code == 200) { var html = template('comment_tpl', res); $('.commont_list').html(html); } else { YDUI.dialog.toast('已退出!', 'none', 1000); }
c、筛选条件:
模板:
{ {data.booking_date | dateFormat:data.booking_date}}
筛选条件:
/*时间戳*/ template.helper('dateFormat', function (timestamp) { var date = new Date(timestamp * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000 Y = date.getFullYear() + '-'; M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'; D = date.getDate() + ' '; return Y + M + D; });
d、输出html内容
模板:
使用#
{ {#data.booking_date | dateFormat:data.booking_date}}
e、直接在行内写判断