前端开发在很多地方多会用到模板,常见的比如jquery的tmplate
ejs也是一个很简洁的模板
另外附上自己写的一段代码:
(function() {
$.get("data/data.json",function(data) {
var html = new EJS({url: "tml/cleaning.ejs"}).render(data);
$("#nihao").append(html);
}, "json");
})();
(function() {
var data = {
"title":"cleaning",
"supplies":["adfa","adfadfadf","afdadfadfasdfwe"]
};
var html = new EJS({url: "tml/cleaning.ejs"}).render(data);
$("#wohao").append(html);
})();
(function() {
var html = new EJS({url: "tml/cleaning.ejs"}).update("#tahao", "data/data.json");
})();
模板例子:
<h1><%= title %></h1>
<ul>
<% for(var i=0; i<supplies.length; i++) { %>
<li>
<%= link_to(supplies[i],"supplies/"+supplies[i]) %>
</li>
<% } %>
</ul>