我使用Mustache.js succusefully顯示HTML,這裏的代碼如果對象在數組中,如何使用Mustache.js?
var mygame = {
player:'viking',
games:[{name:'d1',type:'avg'},{name:'cod7',type:'fps'},{name:'war3',type:'rts'}]
};
var template = '{{player}} is a good guy<br/> <ul>{{#games}}<li>name:{{name}} and type:{{type}} </li>{{/games}}</ul>';
var html = Mustache.to_html(template, mygame);
var con = document.getElementById('container');
con.innerHTML = html;
但我怎麼使用它時,對象是一個數組,像
var mygames = [{name:'d1',type:'avg'},{name:'cod7',type:'fps'},{name:'war3',type:'rts'}];
Mustache.js不能使用數組作爲參數?我不想將我的數組包裹在對象中 – vikingmute 2011-06-10 01:47:04