我有这样的看法:
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');
}
});
编辑:我也有这个问题主干导航错误所以他们可以连接问题