这是JSON:
var data = [
{
"event": {
"name": "txt1",
"data": "2011-01-02",
"address": "Guangzhou Tianhe Mall"
}
},
{
"event": {
"name": "txt2",
"data": "2011-01-02",
"address": "Guangzhou Tianhe Mall"
}
},
{
"event": {
"name": "txt3",
"data": "2011-01-02",
"address": "Guangzhou Tianhe Mall"
}
}
];
我的胡子模板是:
{{#event}}
<div>
<h2>{{name}}</h2>
<span>on {{data}}</span>
<p>{{address}}</p>
</div>
{{/event}
所以上面的模板代码不起作用。我现在要做的是for
循环:
var html = "";
for(var i = 0; i < data.length; i++){
html += Mustache.to_html(tmp, data[i]);
}
有没有更好的方法让它在没有任何循环的情况下工作?