标签:
handlebars Helper用法: http://www.cnblogs.com/iyangyuan/archive/2013/12/12/3471357.html
var d = { user_name: data.user_name, credentials_number: data.credentials_number, credentials_type: credentialsType2, user_address: data.user_address, user_birth_str: data.user_birth_str, user_gender: data.user_gender, }; var tp = Handlebars.compile($("#user_tpl").html()); Handlebars.registerHelper("compare",function(v1,v2,options){ if(v1==v2) { //满足添加继续执行 return options.fn(this); } else { //不满足条件执行else部分 return options.inverse(this); } });
Handlebars.registerHelper("transformat",function(value){ if(value==1) { return "男"; } else if(value==2) { return "女"; } else { return "未设置"; } }); $("#user_content").html(tp(d));
{{#compare user_gender 1}} <span>男</span><input name="user_gender" id="user_gender" value="1" checked="checked" type="radio"> {{else}} <span>男</span><input name="user_gender" id="user_gender" value="1" type="radio"> {{/compare}} {{#compare user_gender 2}} <span>女</span><input name="user_gender" id="user_gender" value="2" checked="checked" type="radio"> {{else}} <span>女</span><input name="user_gender" id="user_gender" value="2" type="radio"> {{/compare}}
标签:
原文地址:http://www.cnblogs.com/zhuiluoyu/p/4843680.html