在同一事件上绑定keyMap,但使用CTRL和不使用CTRL

时间:2018-06-21 07:47:38

标签: extjs sencha-architect keymapping

我想要实现的是将处理程序/函数设置为 Enter 事件,但是就我而言,我想调用两个不同的函数,因此我的计划是设置另一个输入事件以具有 ctrl:true 配置/属性。但这是行不通的,唯一起作用的是最后声明的那个人(因为这是编译器从头到尾读取代码的方式)。

下面是我的代码的简短预览:

Ext.define('mynamespace'{
    extend: 'Ext.window.Window',
    alias: 'widget.myalias',
    requires: [  //all my requires here]

    modal: true,
    keyMapEnabled:true,
    keyMap: {
        Enter: {  //this works if I don't have the keyMap after this
             handler: 'myfunction'
        },
        Enter: {  //this is the one that only works since this is the last event that is initialized after the screen/window is rendered/loaded
             handler: 'myhandler',
             ctrlKey: true
        }
    }
});

我在https://docs.sencha.com/extjs/6.5.1/modern/Ext.mixin.Keyboard.html#method-getKeyMap上尝试过,但是对我而言却没有用。

这是为我工作的人:https://fiddle.sencha.com/#view/editor&fiddle/1tre

1 个答案:

答案 0 :(得分:2)

不能。最好的办法是在处理程序和委托中检查事件:

handler: 'onEnter',

// Later
onEnter: function(e) {
    if (e.ctrlKey) {
        this.onEnterWithCtrl();
    } else {
        this.onEnterWithoutCtrl();
    }
}