我正在用Phonegap,BackboneJS,UnderscoreJS,RequireJS編寫一個Android應用程序。Phonegap,BackboneJS,UnderscoreJS,RequireJS模板問題
我有被傳遞到模板像4個模型的集合:
initialize: function(){
var self = this;
this.collection = new RestaurantsCollection();
this.collection.fetch();
this.collection.on("add reset", this.render, this);
},
render:function() {
this.$el.html(_.template(HomeViewTemplate, {collection: this.collection}));
return this;
},
而且在模板中我有:
<%=collection.length%> //outputs 4
<% collection.each(function(model){ %>
<h1>FOO</h1><br /> //doesnt work at all
<% }); %>
在Chrome中我得到預期的輸出(上圖) ,但是當我在AND模擬器中運行它時,我得到了
<%=collection.length%> //outputs 0
任何建議讚賞。我只是需要一些方面來解決問題。
你撥打正確的渲染後取? – jakee
@jakee是的,我喜歡。我按預期得到頁面,只是收集是空的。 –
如果您在'fetch'成功處理程序中調用'render',會發生什麼情況? –