我有这样的观点:
var PostView = Backbone.View.extend({
template: _.template(postTemplate),
events: {
'click .reply': 'addComment',
'keypress textarea': 'addcommentOnEnter'
},
initialize: function(){
_.bindAll(this, "render", "addcomment" , "addcommentOnEnter");
this.model.bind('change', this.render);
},
addcomment : function(){
this.model.comment($(".post-area").val());
},
addcommentOnEnter : function(e){
if (e.keyCode != 13) return;
this.model.comment($(".post-area").val());
},
render: function(){
this.$el.html(this.template(this.model.toJSON()));
}
});
每当我点击.reply
或按Enter键时,无论何时调用addcomment
或addcommentOnEnter
,我都会在我的控制台上收到错误:
我不知道这意味着什么,但它似乎没有破坏应用程序中的任何内容
var PostModel = Backbone.Model.extend({
urlRoot: '/tweet',
idAttribute: '_id',
defaults: {
name: '',
firstRemark: '',
pictureUrl: '',
postListing: '',
comments: [],
votes: 0,
twitterHandle: '',
votetype: 0,
tags: [],
authorizedUsers: [],
postedBy: '',
dateCreated: '',
authorized: 0,
change: ''
},
initialize: function() {
_.bindAll(this, 'comment');
},
comment: function(comment, sender) {
var commentsArray = this.get('comments');
commentsArray.push({
body: comment,
by: window.user.displayName,
profilePic: window.user.profilePic
});
this.set("comments", commentsArray);
this.save();
this.trigger('change');
}
});
编辑: 我也遇到了这个问题Backbone Navigation Error,因此它们可能是连接问题
答案 0 :(得分:0)
我找到了!在我的其他一个观点中,我有this.model.bind('change', this.render());
而不是this.model.bind('change', this.render)
啊,如此微妙,