How to create shortcut keys in extjs

 ̄綄美尐妖づ 提交于 2019-12-12 04:53:40

问题


I write this code for submit on Enter

 {
    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();
                      }
                 });
         }
     }
   }

What change do I need to do for shortcut keys Like Save(Ctrl + S),Paste(Ctrl +P), Open (Ctrl + O), Exit(Ctrl +X)?


回答1:


You need to write appropriate handler to do the job using KeyMap. Ext 4 code snippet may be as follows -

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

This may Help




回答2:


I think, You will solve your problem by this code

I Give many ways.

You choose suitable one from binding:[{}]

                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
                        }); 
                    }
                }


来源:https://stackoverflow.com/questions/17802058/how-to-create-shortcut-keys-in-extjs

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