对于 HTML 表单和提交按钮,我有以下嵌套的 Backbone 视图:
var Button = Backbone.View.extend({
enable: function() {
this.$el.prop('disabled', false);
return this;
},
disable: function() {
this.$el.prop('disabled', true);
}
};
var Form = Backbone.View.extend({
el: '#login-form',
events: {
'submit': 'submit'
},
initialize: function() {
this.submitBtn = new Button({el: this.$el.find(':submit')});
}
submit: function(e) {
this.submitBtn.disable();
// Do AJAX request and re-enable submit upon completion
// ...
return e.preventDefault();
}
};
问题是,当我单击提交按钮时,出现以下错误:
TypeError: 'undefined' is not a function (evaluating 'n.apply(t,r.concat(o.call(arguments)))')
并且 Form 实例的提交函数永远不会被调用。