gpt4 book ai didi

backbone.js - 无法循环 Backbone 集合

转载 作者:行者123 更新时间:2023-12-02 22:04:29 24 4
gpt4 key购买 nike

看来我无法循环遍历 Backbone 集合。我在多个线程中看到过这个主题,但这些解决方案都没有帮助。

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;
}

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

最佳答案

要获取数组形式的集合内容,请使用方法toJSON(例如:collection.toJSON())

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

collection.each(function( model ) {
console.log(model)
});

如果这没有显示您的完整收藏,那么问题出在您如何在收藏中添加项目,而不是循环逻辑。

关于backbone.js - 无法循环 Backbone 集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16350374/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com