【问题标题】:Extjs : Need a confirmation message before closing the windowExtjs:在关闭窗口之前需要确认消息
【发布时间】:2014-09-16 20:55:18
【问题描述】:

我有一个 Ext.window,我想在用户尝试关闭窗口之前显示一条确认消息,方法是单击窗口中的关闭按钮或顶部的默认 [x] 按钮或 Esc 键。为此,我有以下代码。

              closeWindow: function(){
                       Ext.Msg.show({
                      title: 'Confirm or Cancel',
                      msg: 'Are you sure you want to close this window?',
                      buttonText: {ok: 'Yes', cancel: 'No'},
                      icon: Ext.Msg.WARNING,
                      scope: this,
                      width: 400,
                      fn: function(btn, text){
                      if (btn == 'ok'){
                      clearInterval(this.myIntervalTimer);
                      this.cleanEvents(null, null, this.identifier);
                       this.view.destroy();
                    } else {
                   return;
                }
                }
             });
           }

当我单击窗口中的关闭按钮时,这段代码可以正常工作。但是,当我单击默认的 close[x] 或 esc 键时,由于 extjs 的异步性质,窗口会在显示确认消息之前消失。当确认消息显示时没有窗口,因此它变得无关紧要。我也尝试使用 beforeClose 事件,但没有用。

关于如何在 extjs 中实现这一点的任何建议或想法?谢谢...

【问题讨论】:

    标签: extjs window confirmation


    【解决方案1】:

    请测试以下内容,它对我有用:

        Ext.create('Ext.window.Window', {
             title:'Test'
            ,width:400
            ,height:300
            ,autoShow:true
            ,listeners:{
                beforeclose:function(win) {
                    if(win.closeMe) {
                        win.closeMe = false;
                        return true;
                    }
                    Ext.Msg.show({
                         title:'Close confirmation'
                        ,msg:'Really close?'
                        ,buttons:Ext.Msg.YESNO
                        ,callback:function(btn) {
                            if('yes' === btn) {
                                win.closeMe = true;
                                win.close();
                            }
                        }
                    })
                    return false;
                }
            }
        });
    

    【讨论】:

    • 我会试试这个,然后告诉你结果。因此,只要窗口关闭,就会调用此侦听器。我的窗口中有一个关闭按钮,在这种情况下我应该为该关闭按钮处理程序使用什么代码,因为如果我为该事件说 this.close,则确认消息有可能第一次显示 2 次作为我的按钮处理程序中 this.close() 方法的一部分,然后是在窗口关闭之前发生的默认关闭。
    • 调用win.close() 作为按钮处理程序就足够了。这会触发 beforeclose 事件,因此上述整个逻辑都会启动。
    猜你喜欢
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多