在关闭事件之前显示消息框文本窗口

show message box ext window beforeclose event

本文关键字:消息 文本 窗口 显示 事件      更新时间:2023-09-26

我想显示消息框时,用户点击(X)按钮的ext窗口,并在'确定'按钮的消息框窗口将关闭。我写了代码,但它先关闭窗口,而不是显示消息框。下面是代码:

var assignReportFlag = 0;
var assignReportLoader = function(title,url){   
var panel = new Ext.FormPanel({
    id: 'arptLoader',
    height: 485,
    border: false,
    layout: 'fit',      
    autoScroll: true,
    method:'GET',
    waitMsg: 'Retrieving form data',
    waitTitle: 'Loading...',
    autoLoad: {url: url,scripts: true}
});
var cqok = new Ext.Button({
    text:'OK',
    id:'1',
    handler: function(){            
        if(assignReportFlag == 1){
            assignReportFlag = 0;
            Ext.MessageBox.alert('Status', 'Changes has been saved successfully',showResult);
        }else{
            assignReportWindow.close();         
        }           
    }
});
var assignReportWindow = new Ext.Window({       
    layout:'fit',
    title: title,       
    height:Ext.getBody().getViewSize().height - 60,
    width:Ext.getBody().getViewSize().width-20,
    closable: true,
    modal:true,
    resizable: false,
    autoScroll:true,
    plain: true,
    border: false,
    items: [panel],
    buttons: [cqok],
    listeners:{
        beforeclose:function(){
            if(assignReportFlag == 1){
                assignReportFlag = 0;
                Ext.MessageBox.alert('Status', 'Changes has been saved successfully',showResult);
            }else{
                assignReportWindow.destroy();           
            }
        }
    }
});
function showResult(btn){       
    assignReportWindow.destroy();   
};
assignReportWindow.show();
};

谢谢

在您的beforeclose侦听器中返回false以阻止关闭事件被触发

这对我来说很好。看一看

http://jsfiddle.net/DrjTS/266/

var cqok = new Ext.Button({
text:'OK',
id:'1',
handler: function(){            
        Ext.MessageBox.alert('Status', 'Changes has been saved successfully',showResult);
    }
 });
Ext.create('Ext.panel.Panel', {
title: 'Hello',
width: 200,
renderTo: Ext.getBody(),
items:[
        {
xtype:'button',
text:'SUBMIT',
            handler:function(thisobj)
            {
                Ext.create('Ext.window.Window', {
                id:'W',
                height: 200,
                width: 400,
                layout: 'fit',
                buttons: [cqok],
                listeners:{
                beforeclose:function(){
                            Ext.MessageBox.alert('Status', 'Changes has been saved');
                        }
                }    
                }).show();
            }
        }
       ]
    });
    function showResult(btn){       
    Ext.getCmp('W').destroy();   
    };