1

モデル内にあるネストされたコレクションにデータを入力しようとしています。最後のモデルは別のコレクション内にあります。コードは次のとおりです

App.Models.Bed = Backbone.Model.extend();

App.Collections.Beds = Backbone.Collection.extend({
model: App.Models.Bed,
initialize: function(models, options){
    this.room = options.room;
}
});

App.Models.Room = Backbone.Model.extend();

App.Collections.Room = Backbone.Collection.extend({
url: 'rooms/',
initialize: function(){
    this.on('reset', this.getBeds, this);
},

getBeds: function(){
    this.each(function( room ){
        room.beds = new App.Collections.Beds([], { room: room});
        room.beds.url = 'rooms/' + room.id + '/beds';
        room.beds.fetch();
        console.log(room.beds.toJSON());
    });
}
});

今、私が実行した場合:

var rooms = new App.Collections.Room();
rooms.fetch();
rooms.toJSON();

それは私に人口の多い部屋だけを返しますが、各ベッドにベッドのプロパティはありません。有線のことは、/ rooms / 1 / bedのサーバーにリクエストを送信し、各ベッドを取得することです。

ベッドコレクションを埋めていますか?私は何か間違ったことをしていますか?

あなたの時間の仲間をありがとう。

4

1 に答える 1

2

に渡す必要があるようRoom ModelですRoom Collections

于 2013-02-06T23:23:06.530 に答える