如何创建ExtJS的快捷键(How to create shortcut keys in extjs

2019-10-30 09:55发布

我写这篇文章的代码上输入提交

 {
    fieldLabel : 'Password',
    name : 'j_password',
    inputType : 'password',
    allowBlank : false,
    listeners : {
        'render' : function(cmp) {
                 cmp.getEl().on('keypress', function(e) {
                      if (e.getKey() == e.ENTER) {
                          submitform();
                      }
                 });
         }
     }
   }

我需要什么改变了快捷键做这样Save(Ctrl + S) Paste(Ctrl +P)开放(Ctrl + O) Exit(Ctrl +X)

Answer 1:

你需要编写相应的处理程序使用键盘映射来完成这项工作。 分机4代码段可以如下 -

Ext.onReady(function () {
    var map = new Ext.util.KeyMap(document,{                
            key: [VALUES-ASCII], // this works,
            fn: function(){ alert('key was pressed.!'); }
        }
    );
});

这可能有助于



Answer 2:

我认为,你将这段代码解决您的问题

我给很多方面。

您可以选择从装订适合一个:[{}]

                scope     :  this,
                listeners : {                       
                    afterrender: function(window, options) {
                        this.keyNav = new Ext.util.KeyMap({
                            target: window.el,
                            binding: [{
                                key: [10,13],
                                fn: function(){
                                    alert("Return was pressed");
                                }
                            }, {
                                key: "abc",
                                fn: function(){                                    
                                    alert('a, b or c was pressed');
                                }
                            }, {
                                key: "\t",
                                ctrl:true,
                                fn: function(){
                                     submitform();//'Control + tab was pressed
                                }
                            }, {
                                key: "m",
                                ctrl:true,
                                fn: function(){
                                     submitform();//'Control + m was pressed
                                }
                            }],
                            scope: this
                        }); 
                    }
                }


文章来源: How to create shortcut keys in extjs