【问题标题】:ExtJS Window setActive() not working as expectedExtJS 窗口 setActive() 没有按预期工作
【发布时间】:2012-07-03 11:25:44
【问题描述】:

TL/DR:

调用window.setActive(false) 不会将窗口的active 属性设置为false

详细信息:

我有以下 ExtJS 类继承自 Ext.window.Window

Ext.define('WD.view.TbWindow', {
    extend : 'Ext.window.Window',
    isTbWindow: true,

    title: 'Set Me!!',
    constrain: true, // constrain window to viewport
    autoShow: false,
    maximizable: true,
    minimizable: true,

    renderTo: 'main_panel-body',

    minimize: function() {
        this.hide();
        this.setActive(false);
        this.animateTarget.handleWinMinimize();
    },

    ...

});

在上面的函数minimize中有调用this.setActive(false);

我使用 Chrome 开发者工具来调试代码。在执行this.active 之前是true。行执行后它仍然是true。我正在使用 ExtJS 4.1。

【问题讨论】:

  • 你试过颠倒this.hide();this.setActive(false);的顺序吗?另外,在 minimize 函数中执行 console.log(this),并确保 this 正在评估窗口对象。
  • 最好将alert("called") 添加到minimize 函数中,以确保它被调用。
  • @Waltzy 谢谢你的建议。尝试切换语句的顺序,并检查this 实际上是窗口。但都没有解决问题。
  • 这很奇怪.. @OffTopic,您尝试过使用 Architect 吗? sencha.com/products/architect 非常适合调试 extjs。
  • @Josvic Zammit 我们在工作中大量使用 EXTJS,如果您使用 Sencha 设计器,我必须在这一点上指出,Architect 比设计器更好,它更像是一个完整的 IDE,它在应用程序结构中强制执行最佳实践,并且对 Ext.Direct(如果您使用它)有一些非常好的支持,我们仍然使用 chrome 进行调试,但是将 Aptana(我们以前使用的)中的开发与 Architect 进行比较是不明智的,你不要把你的一生都花在为所有琐碎的东西(如 xtypes 和 layout config 等)参考 API 上,这样你就可以专注于代码,获得 30 天的试用期!

标签: javascript extjs extjs4 extjs4.1


【解决方案1】:

源代码中没有设置 true 或 false 的 active 属性,文档中也没有提及。

setActive: function(active, newActive) {
    var me = this;

    if (active) {
        if (me.el.shadow && !me.maximized) {
            me.el.enableShadow(true);
        }
        if (me.modal && !me.preventFocusOnActivate) {
            me.focus(false, true);
        }
        me.fireEvent('activate', me);
    } else {
        // Only the *Windows* in a zIndex stack share a shadow. All other types of floaters
        // can keep their shadows all the time
        if (me.isWindow && (newActive && newActive.isWindow)) {
            me.el.disableShadow();
        }
        me.fireEvent('deactivate', me);
    }
}

【讨论】:

    【解决方案2】:

    问题在于Ext.WindowManager.getActive() 方法。事实上,在 Web 桌面示例中,Sencha 家伙实际上做了一些不太好的编码来获得实际的活动窗口。我复制了该代码,并开始在我的代码中支持 windows 数组,这解决了我的问题。

    我已经编写了一个(并在其中内置了额外的功能)一个 DesktopMgr 小部件,它继承自 Ext.util.MixedCollection,并充当“桌面管理器”,其中“桌面”意味着任何用于处理多个的 ExtJS 容器窗口、激活、停用、导航到上一个/下一个等

    您可以从此gist 下载和使用DesktopMgr。如果您找到改进它的方法(或要修复的错误!),请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      • 1970-01-01
      • 2012-06-15
      相关资源
      最近更新 更多