Backbone - Collection 未从 JSON 填充

Backbone - Collection not populating from JSON

我正在尝试从 JSON 中填充一个 Backbone collection 来 spotify API return 我。但是,在我尝试填充 collection 之后,我得到了一个 console.log() : playlistSpotify child {length: 1, models: Array[1], _byId: Object}。但是我的 collection 应该包含 3 objects(JSON returned 中的 3 objects)。

知道发生了什么事吗?

JS:

经过一些探索,我在 console.log collection 时看到了 this 东西。我真的不明白发生了什么事。

如有任何帮助,我们将不胜感激! :)

您创建的实例有误。改成下一个:

var playlistCollection = new Playlists2(response.items);
var playlistView = new PlaylistSpotifyView({ model : playlistCollection });

要初始化集合,您只需将一个对象数组作为参数传递给 collection

constructor