`
zixiaolan
  • 浏览: 49685 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Javascript使用技巧

阅读更多
     Template.Util = {//tool type
	format : function (str, model) {//format the template 
		for (var k in model) {
			var re = new RegExp("{" + k + "}", "g");
			str = str.replace(re, model[k])
		}
		return str;
	}
   }


使用方式:
var Template = {
    fn: {
        constant: {
            tab: '<table id={tableId} border=0 cellpadding=1 cellspacing=1 class=tb_datalist></table>'
        }
    }
}

createHoriz: function(item) {
    return $(Template.Util.format(Vc.constant.horizontal, {
        "ULId": item.ULId
    }));
}

好处是构造$jquery对象可以直接用字符串+json对象进行替换,代码清晰
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics