서버로 아약스 요청을하려고합니다. 나는 컬렉션에 fetch()
메서드를 사용하고 있습니다. 그것은 성공적으로 Google 크롬 네트워크 탭을 모니터링 후 서버에서 데이터를 검색합니다.each() 함수가 this.collection에 정의되어 있지 않습니다.
여기에 시나리오가 나와 있습니다.
나는 Model
var Model = Backbone.Model.extend({
urlRoot: '/contacts',
});
collection
아래 ViewTwo
var Collection = Backbone.Collection.extend({
model: Model,
url: '/contacts'
});
ViewOne
var ViewOne = Backbone.View.extend({
initialize: function() {
var collection = new Collection().fetch(); // also tried with these options { wait:true, reset: true, async: false }
new ViewTwo({ collection: collection });
}
});
아래 아래
아래에 있습니다
var ViewTwo = Backbone.View.extend({
initialize: function() {
this.collection.each(this.render, this); // Uncaught TypeError: undefined is not a function
},
render: function() {
console.log(this.model);
}
});
알다시피 나는 Uncaught TypeError: undefined is not a function
오류가 발생합니다.
this.render
이 있으므로 문제가되지 않습니다. 문제는 각각 this.collection
의 기능입니다. 어떻게이 문제를 해결할 수 있습니까?
그래도 문제가 해결되지 않습니다. 여전히 같은 오류. –
@undefinedcorvus 오류를 복제하기위한 피들 생성 – StateLess