Parsing Parse.js绑定错误
我是Backbone.js和Parse的新手,如果我不够具体,我深表歉意 我有一个视图,在初始化时抛出一个TypeError,即使我通过删除有问题的行来修复它,也会在代码中抛出另一个错误,否则这是完全可以接受的 以下是我得到的错误:Parsing Parse.js绑定错误,parsing,backbone.js,typeerror,Parsing,Backbone.js,Typeerror,我是Backbone.js和Parse的新手,如果我不够具体,我深表歉意 我有一个视图,在初始化时抛出一个TypeError,即使我通过删除有问题的行来修复它,也会在代码中抛出另一个错误,否则这是完全可以接受的 以下是我得到的错误: Uncaught TypeError: Cannot call method 'bind' of undefined views.js:59 Uncaught TypeError: Cannot call method 'bind' of undefined vie
Uncaught TypeError: Cannot call method 'bind' of undefined views.js:59
Uncaught TypeError: Cannot call method 'bind' of undefined views.js:59
下面是视图的init函数,第59行和第60行:
initialize: function() {
this.model.bind("reset", this.render, this);
this.model.bind("add", this.appendNewJob, this);
}
如果你需要更多的代码,请在评论中告诉我。
更新:根据请求,my render和appendNewJob函数:
render: function(eventName) {
_.each(this.model.models, function(job){
this.appendNewJob(job);
}, this);
this.delegateEvents();
return this.el;
},
appendNewJob: function(job){
this.$el.append(new JobListItemView({
model: job
}).render());
}
我的路由器:
var AppRouter = Parse.Router.extend({
initialize: function() {
$('#header').html(new HeaderView().render());
},
routes: {
"": "list",
"jobs": "list",
"settings": "viewSettings"
},
list: function() {
var self = this;
FB.getLoginStatus(function(response){
if(response.status === 'connected') {
// logged in.
self.before(function() {
self.showView('#content', new JobListView());
});
} else if(response.status === 'not_authorized') {
// not authorized.
} else {
// not connected.
$('#app').hide();
self.before(function() {
self.showView('#login', new StartView());
});
}
});
},
viewSettings: function() {
var self = this;
FB.getLoginStatus(function(response){
if(response.status === 'connected') {
// logged in.
self.before(function() {
self.showView('#content', new SettingsView());
});
} else if(response.status === 'not_authorized') {
// not authorized.
} else {
// not connected.
$('#app').hide();
self.before(function() {
self.showView('#login', new StartView());
});
}
});
$('#filterBar').hide();
},
showView: function(selector, view) {
if(this.currentView) this.currentView.close();
$(selector).html(view.render());
this.currentView = view;
return view;
},
before: function(callback) {
if(this.jobList) {
if(callback) callback.call(this);
} else {
this.jobList = new JobCollection();
var self= this;
this.jobList.fetch({
success: function() {
var joblist = new JobListView({
model: self.jobList
}).render();
$('#content').html(joblist);
if(callback) callback.call(self);
}
});
}
}
});
更新:我还使用parse js库来代替主干。您正在初始化视图,而没有传入
model
选项。该错误是一个标准的javascript错误,它告诉您在第59行中,this.model
未定义:
this.model.bind("reset", this.render, this);
视图不能有this.model
属性,除非您将模型提供给视图
因此,不是:
new JobListView();
您需要使用
new JobListView({model: <insert your model here>});
newjoblistview({model:});
您肯定需要粘贴更多的代码。您可以将代码粘贴到初始化视图的位置吗。。可能是您的路由器
我刚刚修改了这个问题,因为我忘了添加我使用的是解析库,而不是backbone.js。