バックボーンJSライブラリを使用してページを構築する。 コレクション、ビュー、およびルーターがあります。 そして目標は、ページ内のコレクションのすべてのエントリを一覧表示することです。Backbone Collection.fetch()strange behavior
コレクション
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