我自己从未尝试过,但Ext.FocusManager.focusedCmp看起来很有希望。请注意,您需要先激活它,然后才能通过调用Ext.FocusManager.enable()来使用它
编辑
我认为现在它会更稳定。很遗憾听到它似乎对您没有帮助,但我不明白为什么focusedCmp
应该undefined
准时单击按钮,它应该是按钮。随之而来的是我的错误,您需要访问previousFocusedCmp
.
但它应该起作用,因为它没有魔法......
一个小例子JSFiddle:
Ext.FocusManager.enable();
Ext.create('Ext.form.Panel', {
title: 'Simple Form',
bodyPadding: 5,
width: 350,
// The form will submit an AJAX request to this URL when submitted
url: 'save-form.php',
// Fields will be arranged vertically, stretched to full width
layout: 'anchor',
defaults: {
anchor: '100%'
},
// The fields
defaultType: 'textfield',
items: [{
fieldLabel: 'First Name',
name: 'first',
allowBlank: false
},{
fieldLabel: 'Last Name',
name: 'last',
allowBlank: false
}],
// Reset and Submit buttons
buttons: [{
text: 'Reset',
handler: function() {
console.log('Most likely the button you clicked: ', Ext.FocusManager.focusedCmp, 'The Component that was focused before: ',Ext.FocusManager.previousFocusedCmp );
this.up('form').getForm().reset();
}
}, {
text: 'Submit',
formBind: true, //only enabled once the form is valid
disabled: true,
handler: function() {
var form = this.up('form').getForm();
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);
}
});
}
}
}],
renderTo: Ext.getBody()
});
FocusManger是如何做到的一句话(我们省了keynav):
好吧,一旦他启用,他就会查询整个 DOM 以获取所有可聚焦的组件,并告诉每个组件通知他焦点和模糊的变化。