Extjs 如何在关闭窗口时提示是否关闭

          

Extjs关闭窗口前有一个事件是beforeclose,当返回false时,extjs不再执行关闭操作。

由于使用Ext的show方法是异步执行,因此在异步弹出选择框时,仍然执行了关闭操作。

所以第一步是给窗口对象在   Ext.MessageBox.show 后添加return false;


   openerWin.on("beforeclose", function() {    

           Ext.MessageBox.show({});

            return false; }); 


第二步,在关闭对话框的yes按钮里添加事件 openerWin.close(); 此时会再次调用窗口关闭操作。

第三步,加入控制变量,判断是否触发了关闭操作。


 

代码示例:

             openerWin = Ext.ux.Util.createWindow({
                        id : id,
                        title : appletName,
                        width : this.width + 10,
                        height : this.height + 35,
                        plain : true,
                        closable : true,
                        resizable : true,
                        html : htmlContent
                    });


            var ifclose=false;
            openerWin.on("beforeclose", function() {
            if(ifclose){ return true;}
            Ext.MessageBox.show({
            title : i18n.prompt,
            msg : i18n.ldap_prompt_operation_option,
            buttons : Ext.Msg.YESNO,
            icon : Ext.Msg.WARNIN,
            fn : function(btn) {
                if (btn == 'yes') {
                    ifclose=true;
                    openerWin.close();

                    }
            }

         });
        return false;
            });

你可能感兴趣的:(Extjs 如何在关闭窗口时提示是否关闭)