ExtJS 4, keypress event on container

假装没事ソ 提交于 2019-12-25 12:22:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!