使用主干 JS 库构建页面。我有一个集合、视图和路由器。目标是列出页面中集合的所有条目。
该系列
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
以前有人见过这种类型的问题吗?