无法循环骨干集合

Geo*_*ght 2 backbone.js underscore.js backbone.js-collections

似乎我无法遍历骨干集合.我已经在几个主题中看过这个主题,但这些解决方案都没有帮助.

render:function () {
        this.$el.html(this.template(this.model.attributes));
        var that = this;


        console.log(this.projects.models);
        _.each(this.projects.models, function(model) { console.log(model); });

        return this;
    }
Run Code Online (Sandbox Code Playgroud)

从这个我的控制台只显示数组[2]我希望看到每个模型.有谁知道我在这里做错了什么?

Sim*_*ias 5

为了让您的收藏内容作为数组,使用的方法toJSON(如:collection.toJSON())

接下来,要遍历整个集合,请each在集合实例上使用该方法!

collection.each(function( model ) {
    console.log(model)
});
Run Code Online (Sandbox Code Playgroud)

如果这不显示您的完整集合,那么问题在于如何在集合中添加项目,而不是在循环逻辑中.