0

Backbone.jsを学び始めたばかりです。次のユースケースのバックボーンモデルを作成するにはどうすればよいですか?

  • 状態:[0-n]
    • 名前
    • 郡:[0-n]
      • 名前
      • 都市:[0-n]
        • 名前:
        • 公園[0-n]
          • 名前:

どんな助けでも大歓迎です。これは私が今まで試したことです

window.Team = Backbone.Model.extend({
        initialize: function(){
          this.id = this.get('id');
        }
      });
      window.Teams = Backbone.Collection.extend({model:Team});

      window.Ward = Backbone.Model.extend({
        initialize: function(){
          this.name = this.get('name');
          this.code = this.get('code');
          this.teams = new Teams(this.get('teams'));
        }
      });

      window.Wards = Backbone.Collection.extend({model:Ward});

      window.LGA = Backbone.Model.extend({
        initialize: function(){
          this.name = this.get('name');
          this.wards = new Wards(this.get('wards'));
        }
      });

      window.LGAs = Backbone.Collection.extend({model:LGA});

      window.State = Backbone.Model.extend({
        initialize: function(){
          this.name = this.get('name');
          this.lgas = new Wards(this.get('lgas'));
        }
      });

      window.States = Backbone.Collection.extend({model:State,

        initialize: function(){
          _.bindAll(this, 'fetch_success');
          this.bind('change', this.fetch_success);
        },

        url: function(){
            return "data.json"
        },

        fetch_success:function(){
            var data = Backbone.Syphon.serialize(someViewWithAForm);
            var model = new Backbone.Model(data);
        }
      });

ありがとう

4

1 に答える 1

2

Backbone-relationalモデルの構築/取得方法によっては、モデル間の関係を定義できる に興味があるかもしれません。

ドキュメントから:

Person = Backbone.RelationalModel.extend({
    relations: [
        {
            type: 'HasMany',
            key: 'jobs',
            relatedModel: 'Job',
            reverseRelation: {
                key: 'person'
            }
        }
    ]
});
于 2012-06-20T16:40:30.163 に答える