【发布时间】:2013-07-09 06:50:23
【问题描述】:
对于渲染函数中的 jquery-ui 对话框,我可以使用指向另一个函数而不是内联它的按钮吗?
var MyView = Backbone.View.extend({
submit: function(event) { /* foo */ },
buttons: [{
'text' : 'SUBMIT',
'click' : this.submit // <== like this
}],
render: function() {
this.$el.append("I'm a dialog with a button").dialog({ buttons: this.buttons });
return this;
}
});
我按原样运行上面的代码,好像引擎找不到submit:
Uncaught TypeError: Cannot call method 'apply' of undefined jquery-ui.js:10018
$.widget._createButtons.$.each.props.click jquery-ui.js:10018
jQuery.event.dispatch jquery-1.9.1.js:3074
jQuery.event.add.elemData.handle jquery-1.9.1.js:2750
【问题讨论】:
-
关于这个问题的一点背景:我按原样运行了上面的代码,似乎引擎找不到提交:未捕获的类型错误:无法调用未定义 jquery-ui.js:10018 的方法“应用” $.widget._createButtons.$.each.props.click jquery-ui.js:10018 jQuery.event.dispatch jquery-1.9.1.js:3074 jQuery.event.add.elemData.handle jquery-1.9.1.js :2750
标签: jquery-ui backbone.js dialog