Extjs 按键导航,按键盘上的Enter键时的事件

Extjs 按键导航,按键盘上的Enter键时的事件,extjs,keyboard,Extjs,Keyboard,您好,我想在键盘上按Enter键进行活动。我要这样做: listeners: { afterRender: function (thisForm, options) { this.keyMap = Ext.create( 'Ext.util.KeyMap', this.el, [ { key: 13,

您好,我想在键盘上按Enter键进行活动。我要这样做:

 listeners: {
    afterRender: function (thisForm, options) {
        this.keyMap = Ext.create(
            'Ext.util.KeyMap',
            this.el,
            [
                {
                    key: 13,
                    fn: this.submitOnEnter,
                    scope: this
                }
            ]
        );
    }
},

submitOnEnter: function (e) {
    if (e === 13) {
        console.log('some event there!!!')
    }

},

但当我按Enter键时,什么也不会发生。

如果是文本字段、组合框、触发器或其他内容,您可以尝试为specialkey添加一个侦听器:

        listeners:{  
            specialkey: function(f,e){  
                if(e.getKey()==e.ENTER){  
                    console.log("I hit enter!"); 
                }  
            }  
        }, 

如果它只是在窗口的任何地方按回车键,那么我就不太确定了。类似的方法可能会起作用。

您是要将keylistener添加到表单还是表单字段?您使用的是什么版本的ExtJS?更多的代码会有所帮助。看看这个家伙的解决方案:他使用S键,但你可以将其更改为ENTER的数字。他还有“ctrl:true”的意思,意思是你必须点击ctrl-S。如果你不想点击,请删除它。我把他的“启动”部分的代码放在我的主应用程序的“初始化”函数中。