我有显示对话框的简单视图。
Backbone.View.prototype.completeRemove = function(){
this.undelegateEvents();
this.remove();
delete this.$el;
delete this.el;
console.log('completely removed')
}
MdApp.dialogBox = Backbone.View.extend({
defaults: {
text: __('No text provided'),
buttonText: __('Ok'),
callback: function(){
return null;
},
el: $('#app-panel'),
type: 'error',
cancellable: false,
cancelText: __('No'),
picture: pic('default')
},
el: '<div class="dialog-box">',
template: _.template($('#dialog-box-template').html()),
events: {
'click .confirm' : 'confirm',
'click .cancel' : 'cancel'
},
initialize: function(){
this.model = _.extend(this.defaults, this.model);
this.render();
},
render: function(){
var model = this.model;
this.$el.html(this.template(model));
model.el.append(this.el);
},
confirm: function(){
var model = this.model;
var view = this;
this.completeRemove();
model.callback();
},
cancel: function(){
this.completeRemove();
}
});
它有自己的默认值。每次我初始化新对话框时,它的值都会在每个对话框调用之间保持不变。例如,当我第一次调用对话框时:
new MdApp.dialogBox({model:{
text: __('Do you really wanna delete this?'),
buttonText: __('Unfortunately yes'),
callback: function(){
//some callback
},
cancellable: true,
cancelText: __('No'),
picture: pic('confirm delete')
}});
之后,我将调用另一个没有cancellable
属性的对话框,因此它应该使用默认对话框(即false
),但它保持不变。这适用于所有其他财产。为什么会这样?