백본 JS 라이브러리를 사용하여 페이지를 빌드합니다. 컬렉션,보기 및 라우터가 있습니다. 그리고 목표는 페이지에서 컬렉션의 모든 항목을 나열하는 것입니다.백본 Collection.fetch() 이상한 동작
컬렉션
window.Artifact = Backbone.Model.extend({
urlRoot:"/rest/artifacts",
initialize:function(){
this.artifacts = new ArtifactCollection();
}
});
window.ArtifactCollection = Backbone.Collection.extend({
model:Artifact,
url:"/rest/artifacts"
});
var artifacts = new ArtifactCollection;
뷰
window.findView = Backbone.View.extend({
initialize:function() {
console.log('Initializing Find View');
this.template = _.template(tpl.get('find'));
},
render:function (eventName) {
var data = { 'data' : artifacts.models };
$(this.el).html(this.template(data));
return this;
}
});
라우터 프로그램
var AppRouter = Backbone.Router.extend({
routes:{
"":"home",
"contact":"contact",
"get":"get",
"find":"find",
"requests/:id":"requests"
},
find:function(){
artifacts.fetch({
success:function(){
this.findView = new findView();
this.findView.render();
$('#content').html(this.findView.el);
}
});
},
문제는 대부분의 시간 작동하지만 때로는 작동하지 않습니다이다. 그것은 누군가가 전에 이러한 유형의 문제를 본
Uncaught TypeError: object is not a function
artifacts.fetch.successmain.js:53
_.extend.fetch.options.successbackbone-0.9.2.js:760
jQuery.Callbacks.firejquery.js:1032
jQuery.Callbacks.self.fireWithjquery.js:1150
donejquery.js:7385
jQuery.ajaxTransport.send.callback
다음과 같은 예외가 발생합니다?
잠깐, 이슈 모델에 인공물 모음이 있습니까? – asawyer
ArtifactCollection은 인공물 모음 – Nambi
을 가리켜 주셔서 감사합니다. 나는 그것을 제거해야한다. – Nambi