Backbone.js Collection of Collections

前端 未结 1 1651
星月不相逢
星月不相逢 2020-12-12 21:02

I\'m trying to figure out how to make a Collection of collections with backbone.js. I\'m pretty new to backbone. I have something like the following situation:



        
相关标签:
1条回答
  • 2020-12-12 21:41

    You'd solve your problem by turning your Playlist from a collection into a model. If you think about it, a Playlist would probably have other attributes anyway (e.g. name) that wouldn't be settable on a collection.

    Playlists would then be a collection of Playlist models (instead of collections), which should work without error.

    var Track = Backbone.Model.extend({
        //trackdata
    });
    
    var Playlist = Backbone.Model.extend({
        model : Track
    });
    
    var Playlists = Backbone.Collection.extend({
        url   : "playlists",
        model : Playlist
    });
    
    0 讨论(0)
提交回复
热议问题