问题
I'm using ExtJS 4.1 MVC and I need to perform some actions after user click Enter button.
I did it this way:
Ext.getDoc().on('keypress', function(event, target) {
me._enterKeyHandler(event, target, me);
});
But I wonder if somehow I can use Ext.util.KeyMap in Container. In Sencha docs I found something and tried, but it didn't work for me.
var map = new Ext.util.KeyMap({
// in target I tried: Ext.getCmp('myComponent'), "myComponent", myComponentVar
target: "my-element",
key: Ext.EventObject.ENTER,
fn: function() {alert('enter')}
});
So, how how can I listen to keyPress event bot using 'document' ? Help me, please
回答1:
Ext.util.KeyNav works for me. For example, in a panel:
afterRender: function () {
this.callParent(arguments);
this.keyNav = Ext.create('Ext.util.KeyNav', this.el, {
enter: this.onSubmitButton,
scope: this
});
}
This binds the "Enter" key to the onSubmitButton function in the panel.
来源:https://stackoverflow.com/questions/21239698/extjs-4-keypress-event-on-container