Javascript this.up()不是函数EXTJS
我想从控制器向服务器提交数据。 代码如下:Javascript this.up()不是函数EXTJS,javascript,extjs,web-applications,extjs4,sencha-touch,Javascript,Extjs,Web Applications,Extjs4,Sencha Touch,我想从控制器向服务器提交数据。 代码如下: renterForms: function() { var items3 = [{ xtype:'foresto-renterdata', scrollable: true, scope: this, renderTo: 'mainPart', handler: function() { this.action3.hide();
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调试器中,我看到下一个错误:
未捕获类型错误:this.up不是函数。怎么了?这是获取和提交数据的好方法吗 POST请求的p.S.url在表单代码中定义 范围:本 这是一个实际的问题,它正在搞乱处理函数中的作用域。移除它,它将解析up函数 您可以通过以下示例fiddle查看scope的行为:
当定义了作用域时,则在构建组件时将使用作用域,并将其注入处理函数中。这相当于显式编写handlerFn.bind(this),它只是绑定不同的作用域并返回一个新函数。将该
处理程序
函数改为箭头函数,要保留周围作用域的this
,如果您不介意,请显示它的外观,而不是handler:function(){…}
dohandler:()=>{…}
。看到了吧,当我得到你的答案时,我已经明白了它是如何工作的。格雷西奥!