我想从 Controller 将数据提交到服务器。 代码如下:
renterForms: function() {
var items3 = [{
xtype:'foresto-renterdata',
scrollable: true,
scope: this,
renderTo: 'mainPart',
handler: function() {
this.action3.hide();
}
},{
text: 'Submit',
ui: 'confirm',
scope: this,
handler: function() {
var form = this.up('foresto-rentertype');
if (form.isValid()) {
form.submit({
success: function(form, action) {
Ext.Msg.alert('Success', action.result.msg);
},
failure: function(form, action) {
Ext.Msg.alert('Failed', action.result.msg);
}
});
} else { /
Ext.Msg.alert('Error', 'Please correct form errors.')
}
}
在 Chrome 调试器中,我看到下一个错误:
Uncaught TypeError: this.up is not a function.
出了什么问题?这是获取和提交数据的好方法吗?
附注POST 请求的 url 在表单代码中定义
最佳答案
scope: this
这是扰乱处理程序函数内部范围的实际问题。去掉它就可以解决up函数了。
您可以使用以下示例 fiddle 查看具有范围的行为: https://fiddle.sencha.com/#view/editor&fiddle/2nhv
当定义“scope:this”时,构建组件时的范围将被使用并注入(inject)到处理函数中。它相当于显式编写 handlerFn.bind(this) ,它只是绑定(bind)不同的作用域并返回一个新函数。
关于javascript - this.up() 不是函数 EXTJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53204369/