当我尝试使用骨干js创建集合集合时,我遇到了一个问题.这是代码:
模特和收藏:
var Track = Backbone.Model.extend({
defaults : {
title : ""
}
})
var TrackCollection = Backbone.Collection.extend({
model : Track,
})
var Playlist = Backbone.Model.extend({
defaults : {
name : "",
tracks : new TrackCollection,
}
})
var PlaylistCollection = Backbone.Collection.extend({
model : Playlist,
})
Run Code Online (Sandbox Code Playgroud)
创建播放列表集合:
var playlists = new PlaylistCollection;
// create and push the first playlist
playlists.push({ name : "classic" });
// create and push a track in the playlist just created
playlists.last().get("tracks").push({ title : "fur elise" …Run Code Online (Sandbox Code Playgroud)