我有一个包含用户名和密码的两个字段的表单。我有一个带有处理程序的 [loginbutton]。如何从登录按钮的处理程序中的字段中获取这些值,以便为控制器触发事件?
handler: function() {
var form = this.parent.parent;
//HOW TO GET THESE VALUES?
var username = form.user;
var password = form.password;
form.fireEvent('login', username, password);
}
使用调试器,我发现这是可行的,但对我来说似乎是一个非常复杂的解决方案:
handler: function() {
var form = this.parent.parent;
var fieldset = form.items.items[0];
var username = fieldset.innerItems[0]._component._value;
var password = fieldset.innerItems[1]._component._value;
form.fireEvent('login', username, password);
这是带有配置声明的代码。
Ext.define('AddressBook.view.Login', {
title: "Luminizer Login",
extend: 'Ext.form.Panel',
xtype: 'loginForm',
config: {
url: 'login.php',
standardSubmit: false,
items: [
{
xtype: 'fieldset',
title: 'MyCompony',
instructions: 'Log in with username and password.',
defaults: {
required: true,
labelAlign: 'left',
labelWidth: '40%'
},
items: [
{
//SCROLL DOWN FOR HANDLER
xtype: 'textfield',
name: 'name',
label: 'Name',
value: 'user',
autoCapitalize: false
},
{
xtype: 'passwordfield',
name: 'password',
label: 'Password',
value: 'test'
}
]
},
{
xtype: 'toolbar',
docked: 'bottom',
items: [
{xtype: 'spacer'},
{
text: 'Reset',
handler: function() {
form.reset();
}
},
{
text: 'Login',
ui: 'confirm',
handler: function() {
var form = this.parent.parent;
//HOW TO GET THESE VALUES?
var username = form.user;
var password = form.password;
form.fireEvent('login', username, password);
}
}
]
}
],
...
}