백본이 컬렉션에 지정된 모델을 사용하고 있지 않습니다. 나는 뭔가를 놓치고 있어야합니다.Backbone.js 컬렉션 모델 값이 사용되지 않습니다.
App.Models.Folder = Backbone.Model.extend({
initialize: function() {
_.extend(this, Backbone.Events);
this.url = "/folders";
this.items = new App.Collections.FolderItems();
this.items.url = '/folders/' + this.id + '/items';
},
get_item: function(id) {
return this.items.get(id);
}
});
App.Collections.FolderItems = Backbone.Collection.extend({
model: App.Models.FolderItem
});
App.Models.FolderItem = Backbone.Model.extend({
initialize: function() {
console.log("FOLDER ITEM INIT");
}
});
var folder = new App.Models.Folder({id:id})
folder.fetch();
// later on change event in a view
folder.items.fetch();
폴더가로드는 항목은 다음로드 있지만 호출되지 않습니다 개체 및 폴더 항목 INIT를 FolderItem되지 않습니다. 그것들은 기본 Model 객체입니다.
무엇을 놓쳤습니까? 나는 이것을 다르게해야 할까?
편집 : 왜 이것이 작동하는지는 잘 모르겠지만 다음과 같은 이유가 있습니다. 백본 5.3
App.Collections.FolderItems = Backbone.Collection.extend({
model: function(attributes) {
return new App.Models.FolderItem(attributes);
}
});
아, 맞아. 감사! – Candland
이것은 나를 잡았습니다. 그것은 매우 비밀스러운 오류를 일으켰습니다. 나는 이것을 문서에서 강조해야한다고 생각한다. – UpTheCreek