ExtJS 6 - 隐藏组件时停止事件委托?

ExtJS 6 - Stop Event Delegation while hiding component?

我必须在它的模糊事件中隐藏相同的字段。

Extjs 6 在组件隐藏方法上调用事件委托。Event delegation revert focus to last field which had focus

而且,我不想恢复焦点。在 extjs 中隐藏元素时,有什么方法可以 stop event delegation 吗?

事件委托是 extjs 5 自带的 - Delegated Events and Gestures in Ext JS 5

用于隐藏的方法 - https://docs.sencha.com/extjs/6.0/6.0.1-classic/#!/api/Ext.Component-method-onHide

ExtJS 源代码中的 onHide() 方法 - 检查 revertFocus()

onHide: function(animateTarget, cb, scope) {
    var me = this,
        ghostPanel, fromSize, toBox;
    if (!me.ariaStaticRoles[me.ariaRole]) {
        me.ariaEl.dom.setAttribute('aria-hidden', true);
    }
    // Part of the Focusable mixin API.
    // If we have focus now, move focus back to whatever had it before.
    me.revertFocus(); // this revert focus making probelm
    // Default to configured animate target if none passed
    animateTarget = me.getAnimateTarget(animateTarget);
    // Need to be able to ghost the Component
    if (!me.ghost) {
        animateTarget = null;
    }
    // If we're animating, kick off an animation of the ghost down to the target
    if (animateTarget) {
        toBox = {
            x: animateTarget.getX(),
            y: animateTarget.getY(),
            width: animateTarget.dom.offsetWidth,
            height: animateTarget.dom.offsetHeight
        };
        ghostPanel = me.ghost();
        ghostPanel.el.stopAnimation();
        fromSize = me.getSize();
        ghostPanel.el.animate({
            to: toBox,
            listeners: {
                afteranimate: function() {
                    delete ghostPanel.componentLayout.lastComponentSize;
                    ghostPanel.el.hide();
                    ghostPanel.setHiddenState(true);
                    ghostPanel.el.setSize(fromSize);
                    me.afterHide(cb, scope);
                }
            }
        });
    }
    me.el.hide();
    if (!animateTarget) {
        me.afterHide(cb, scope);
    }
},

当模糊事件触发时,在 viewcontroller 调用的函数中使用 suspendEventsresumeEvents

不是 stopEventssuspendEvents。我的错。 :P

blurEventFunction:function(cmp){
    cmp.suspendEvents();
    cmp.hide();
    camp.resumeEvents();
}

你做错了,revertFocus()是一个主要的问题根源。解决方案可能是:

blurEventFunction:function(cmp){
    cmp.previousFocus = null;
    cmp.hide();
}

我遇到了同样的问题。 (extjs 6.5.1 - 使用模态 window 和 closeAction:'hide')

我正在调试代码,它似乎发生了,因为最近关注的字段在一个面板中,而我的模态 window 不是该面板的子项。 (似乎 extjs 获取模态 window 的祖先以找到最新的焦点字段,然后设置焦点)

当我将 window 添加到该面板时,它运行良好。 (当模式 window 关闭时,焦点在打开 window 之前的最新字段上。

调试 Ext.util.Focusable class,我看到了一个名为 preventRefocus 的配置。如果您将值为 true 的配置添加到模态 window,则 revertFocus 函数的内容将不会被执行,您也不会收到错误。

revertFocus: function() {
        var me = this,
            focusEvent = me.focusEnterEvent,
            activeElement = Ext.Element.getActiveElement(),
            focusTarget, fromComponent, reverted;

        // If we have a record of where focus arrived from, 
        //  and have not been told to avoid refocusing, 
        //  and we contain the activeElement. 
        // Then, before hiding, restore focus to what was focused before we were focused. 

        // --->>> THE IF BELOW: !me.preventRefocus <<<---

        if (focusEvent && !me.preventRefocus && me.el.contains(activeElement)) {

我希望它也能帮助到未来的人。