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/beds에있는 서버에 요청을 보내고 각 침대를 되 찾는다는 것입니다.
침대 컬렉션을 채우고 있습니까? 내가 잘못하고 있니?
시간가는 데 감사드립니다.
감사합니다. jaja, 어리석은 실수 – Pablo
모두와 함께 발생합니다. :) –