1

我想在用户单击 ext 窗口的 (X) 按钮时显示消息框,并且消息框窗口的“确定”按钮将关闭。我编写了代码,但它首先关闭窗口而不是显示消息框。这是代码:

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();
};

谢谢

4

2 回答 2

2

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

于 2013-05-17T11:26:23.160 回答
0

这对我来说很好。看看

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();   
    };
于 2013-05-17T11:43:01.827 回答