Android Phonegap、BackboneJS、下划线JS和模板的RequireJS问题

Android Phonegap、BackboneJS、下划线JS和模板的RequireJS问题,android,cordova,backbone.js,requirejs,underscore.js,Android,Cordova,Backbone.js,Requirejs,Underscore.js,我正在用Phonegap、BackboneJS、下划线JS和RequireJS编写一个Android应用程序 我收集了4个模型,这些模型被传递到一个模板,如: initialize: function(){ var self = this; this.collection = new RestaurantsCollection(); this.collection.fetch(); this.collection.on("a

我正在用Phonegap、BackboneJS、下划线JS和RequireJS编写一个Android应用程序

我收集了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
<% }); %>
//输出4
FOO
在Chrome中,我得到了预期的输出(如上),但当我在和模拟器中运行它时,我得到了

<%=collection.length%> //outputs 0
//输出0

如有任何建议,我们将不胜感激。我只是需要一些关于问题可能是什么的指导。

够傻了,集合中的URL是/my URL,并将其更改为my URL解决了问题。

我实际上找到了我答案的解决方案,如下所示:

错误:

<%=collection.length%> //outputs 4
<% collection.each(function(model){ %>
<h1>FOO</h1><br /> //doesnt work at all
<% }); %>
//输出4
FOO
正确

<%=collection.length%> //outputs 4
<% _.each(colleciton.models, function(model){ %>
<%console.log(model.get('id'))%>
<% }); %>
//输出4

你会在抓取后立即调用render吗?@jake是的,我会。我按预期得到页面,只是集合是空的。如果改为在
fetch
success处理程序中调用
render
,会发生什么情况?它就像
collection.fetch();这个。render()?@muistooshort然后//在Chrome和仿真器中输出0