gpt4 book ai didi

extjs - 从 ExtJS Controller 中的点击事件获取表单?

转载 作者:行者123 更新时间:2023-12-01 01:16:49 25 4
gpt4 key购买 nike

我正在扩展 http://docs.sencha.com/architect/2-0/#!/guide/views_forms_extjs 中给出的示例使用更以 MVC 为中心的方法。因此,为此我想将点击处理程序从 View 移动到新创建的 Controller 。

我的点击甚至工作正常,但我不知道如何从 Controller 的上下文中操作表单( View 使用 this.getForm())。

这是我到目前为止所拥有的

Ext.define('LoginExample.controller.LoginController', {
extend: 'Ext.app.Controller',


onLoginButtonClick: function(button, e, options) {
console.log('button clicked');


if (this.getForm().isValid()) {
this.getForm().submit({
url: 'login.php',
success: function(form, action) {
Ext.Msg.alert('Login Successful!');
},
failure: function(form, action) {
Ext.Msg.alert('Login Failed!');
}
});
}
},


init: function() {
this.control({
"#loginButton": {
click: this.onLoginButtonClick
}
});
}

});

显然,onLoginButtonClick 上下文中的 this 不再是 View ,而是 Controller 。

给定给我的参数(Ext.button.Button 按钮、事件 e、对象选项),我如何在适当的表单上提交?

我应该使用 ExtJS 4 来注意这一点。

最佳答案

button.up('form');

会做的伎俩。

要获得要操作的 BasicForm 对象,请使用

button.up('form').getForm()

关于extjs - 从 ExtJS Controller 中的点击事件获取表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11547795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com