码迷,mamicode.com
首页 > 其他好文 > 详细

handlebars Helper用法

时间:2015-09-28 13:12:17      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:

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}}   

 

handlebars Helper用法

标签:

原文地址:http://www.cnblogs.com/zhuiluoyu/p/4843680.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!