Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 主干模板不变_Backbone.js_Backbone Views_Backbone Events - Fatal编程技术网

Backbone.js 主干模板不变

Backbone.js 主干模板不变,backbone.js,backbone-views,backbone-events,Backbone.js,Backbone Views,Backbone Events,我对一个事件有看法 events: { 'click button.add-prediction': 'addPrediction' }, addPrediction: function(event) { var currentPredictions = this.model.get('count'); this.model.set('count', currentPredictions + 1); this.$el.find('.add-prediction'

我对一个事件有看法

events: {
    'click button.add-prediction': 'addPrediction'
},
addPrediction: function(event) {
    var currentPredictions = this.model.get('count');
    this.model.set('count', currentPredictions + 1);

    this.$el.find('.add-prediction').html('predicted').addClass('selected');
},
这样做:

this.$el.find('.add-prediction').html('predicted').addClass('selected');
似乎不太合适,但当我这么做的时候

$(event.target).html('predicted').addClass('selected');
DOM没有更新,为什么?我做错了什么

这是完整的视图

Event.Views.PredictionsView = Backbone.View.extend({
tagName: 'div',
className: 'stats',
events: {
    'click button.add-prediction': 'addPrediction',
    'click button.add-prediction.selected': 'removePrediction'
},
initialize: function() {
    this.model.on('change', this.render, this);
},
removePrediction: function() {
    var currentPredictions = this.model.get('count');
    this.model.set('count', currentPredictions - 2);

    this.$el.find('.add-prediction').html('Predict').removeClass('selected');
    this.$el.removeClass('selected');
    this.$el.parent().find('.add-prediction').removeAttr('disabled');
},
addPrediction: function() {
    var currentPredictions = this.model.get('count');
    this.model.set('count', currentPredictions + 1);

    this.$el.find('.add-prediction').html('Remove prediction').addClass('selected');
    this.$el.addClass('selected');
    this.$el.parent().find('.add-prediction:not(.selected)').attr('disabled', 'true');

},
setTemplate: function() {
    var that = this;
    $.get('templates/singleEvent/team-details.html', function(data) {
        that.template = _.template(data);
        that.render();
    }, 'html');
    return this;
},
render: function() {
    var eventTemplate = this.template(this.model.toJSON());
    $(this.el).html(eventTemplate);
    return this;
}
}))

不幸的是,我不能制作jsFid,因为它太复杂,要使它工作需要很长时间。
多谢各位

event.target不引用按钮

事件。目标[0]引用按钮

设法

$(event.target[0]).html('predicted').addClass('selected');


您的按钮可能有一个img或其他元素在其中,事件正在该按钮上触发。这是event.target将引用的内容,而不是您期望的按钮元素。否event.target引用的按钮
0:button.btn.btn quarter.btn good。添加预测
您能提供更多详细信息吗?甚至可能是JSFIDLE.net上的一个最小但功能性的演示?我可以尝试,但这将很困难,这是一个非常长的项目:/render函数看起来怎么样?
event.target.html('predicted').addClass('selected');