使用骨幹JS庫來構建頁面。 我有一個集合,視圖和路由器。 目標是列出頁面中所有集合的條目。Backbone 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