artTemplate(js模板引擎)如何添加方法
seajs.use("template", function(template) { template.helper("moneyFormat",function(numStr){ if (numStr === 0) { return '0.00'; } else { var numStr = String(numStr); $.trim(numStr).replace(/\,/g, ''); if (numStr.length > 20) { numStr = numStr.substring(0, 10); } var re = /\d{1,3}(?=(\d{3})+$)/g; var n1 = numStr.replace(/^(\d+)((\.\d+)?)$/, function(s, s1, s2) { return s1.replace(re, "$&,") + s2; }); return n1; } }) var allhtml = template('tpl-rec', oContent); currentCon.append(allhtml); })
使用:
<em class="red">¥</em><em class="red paddL10">{{value[1] | moneyFormat}}</em>