我有一个下划线模板,我必须使用 Mustache来渲染它。下面是我的下划线模板:
<div id="sub-account">
<p>something</p>
<table>
<tr><td>Name</td>
</tr>
<tbody>
<% _.each(accountList, function(account) { %>
<tr>
<td><%= account.get('name') %></td>
</tr>
<% }) %>
</tbody>
</table>
</div>
我使用 mustache 作为我的主要 View 来渲染列表。如何循环代码以呈现为 mustache 模板?
主干集合:
var SubAccountCollection = Backbone.Collection.extend({
initialize: function(models, options) {
this.account = options.id;
},
url: function() {
return 'some/' +this.account + '/somelist';
}
});
return SubAccountCollection;
});
这就是我试图用ajax调用做的事情:
accountList.fetch({
success: function(accnlist){
setInterval(function(){
$('#sub-account-list').html(tmpl, {accnlist:accnlist.toJSON()})
}, 500);
},
error: function(err){
console.log('Error!', err)
}
});
最佳答案
应该是这样的。不过没查。
<div id="sub-account">
<p>something</p>
<table>
<tr><td>Name</td>
</tr>
<tbody>
{{#accountList}}
<tr>
<td>{{name}}</td>
</tr>
{{/accountList}}
</tbody>
</table>
</div>
关于javascript - 如何完成从下划线模板到 mustache 的For-Each循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24132069/