Mustache
Mustache是一个模板库,用起来非常的简单
它可以很好的把数据,html页面分开,然后就是进行页面分割来,进行前端MVC模型开发来,加上框架backbone的MVC功能,前端就可以进行MVC模型开发了。
现在我简单地讲解下我今日对Mustache的学习情况
一个简单的例子:
var person = {
firstName: "Christophe",
lastName: "Coenraets",
blogURL: "http://coenraets.org"
};
var template = "<h1>{{firstName}} {{lastName}}</h1>Blog: {{blogURL}}";
var html = Mustache.to_html(template, person);
$('#sampleArea').html(html);
输入出结果:
Christophe Coenraets
Blog: http://coenraets.org
数据为person,模板是template,html是需要显示到页面的html代码
但是和backbone怎么混合一起使用,还在研究中,下一章待续。。