mustache小结

遇到一个用mustache写的写的项目,感觉很好用,网上查了下发现干货不多,所以自己汇总了一下。

以下是几个案例:引用的js,下载位置,jquery应该都有,贴一下mustache的下载位置:https://github.com/janl/mustache.js

$(function(){

	var tmple = $('#tmple').html();
	Mustache.parse(tmple);
	
	//读取普通数据
	var data={"name":"张三"}
	var rendered = Mustache.render(tmple, data);
    $("#tmpleHtml").html(rendered);

    //读取数组
    data=[
    			{"name":"张三",
    		     "age":"18",
    		     "sex":"男"},
    			{"name":"李四",
    			 "age":"19",
    		     "sex":"男"},
    			{"name":"王五",
    			 "age":"20",
    		     "sex":"女"},
    		]
	var rendered = Mustache.render(tmple, {list:data});
    $("#tmpleHtml").html(rendered);

    //读取二数组
    data=[
    			{
    		     "id":1,
    			 "name":"张三",
    		     "age":"18",
    		     "sex":"男",
    		     "friends":[{
    		     	"name":"张三朋友一",
    		     	"age":"18",
    		     	"sex":"男",
    		     },{
    		     	"name":"张三朋友二",
    		     	"age":"18",
    		     	"sex":"男",
    		     }]},
    			{
    			 "id":2,
    			 "name":"李四",
    			 "age":"19",
    		     "sex":"男",
    		 	 "friends":[{
    		     	"name":"李四朋友一",
    		     	"age":"18",
    		     	"sex":"男",
    		     }]},
    			{
    			 "id":3,
    			 "name":"王五",
    			 "age":"20",
    		     "sex":"女",
    		     "friends":[{
    		     	"name":"王五朋友一",
    		     	"age":"18",
    		     	"sex":"男",
    		     }]},
    		]
	var rendered = Mustache.render(tmple, {list:data});
    $("#tmpleHtml").html(rendered);

	var friends = $('#friends').html();
    for(var i=0;i







Mustache测试


  
  

 

	
	
 

 

 

你可能感兴趣的:(mustache小结)