How to build a Collection/Model from nested JSON with Backbone.js

前端 未结 3 1955
旧巷少年郎
旧巷少年郎 2020-12-07 23:58

I\'m relativly new to Backbone.js

I have a JSON like the picture shows ! I saw some Answers in relation with Backbone-relational, but still dont ge

3条回答
  •  有刺的猬
    2020-12-08 00:08

    I'm at work, so I cannot give you a fully coded answer, but the gist is, you can do the following in your top level models to achieve a nested model hierarchy:

    var AmericasNextTopModel = Backbone.Models.extend({
        initialize: function(){
    
            this.set({
                 clefs: new ClefCollection(this.get('clefs')),
                 accidentals: new AccidentalCollection(this.get('accidentals')),
                 notes: new NoteCollection(this.get('notes')),
                 rests: new RestCollection(this.get('rests'))
            });
        }
    });
    

    I do not use backbone-relational so I cannot give you an answer regarding that.

    Are you making an online sheet music viewer/editor? :D Cool I'd love to see it when you're done.

提交回复
热议问题