【问题标题】:Window is not closing properly second time窗口第二次没有正确关闭
【发布时间】:2016-09-20 09:58:57
【问题描述】:

我想在点击按钮时打开一个新窗口。在 cclick 上的按钮窗口打开和关闭正常,但第二次没有正确关闭。

这是我的代码

var formPanel = new Ext.FormPanel({
    height: 125,
    autoScroll: true,
    id: 'formpanel',
    defaultType: 'field',
    frame: true,
    title: 'CheckOut from SVN',
    items: [{
        fieldLabel: 'SVN Path'
    }],
    buttons: [{
        text: 'Submit',
        minWidth: 75,
        handler: function() {

            var urlTemp = './Export?' + '&' + fp.getForm().getValues(true);
            formPanel.getForm().submit({
                url: urlTemp,
                method: 'Post',
                success: successFn1,
                timeout: 18000000,
                failure: otherFn
            });
        }
    }, {
        text: 'Reset',
        minWidth: 75,
        handler: function() {
            formPanel.getForm().reset();
        }
    }]
});


function buildWindow() {

    var win = new Ext.Window({
        id: 'newWindow',
        layout: 'fit',
        width: 300,
        height: 200,
        closeAction: 'hide',
        plain: true,
        stateful: false,
        items: [formPanel]
    });

    win.show();
}

var extSVN = new Ext.Button({
    text: 'Checkout from SVN',
    minWidth: 75,
    handler: function() {
        buildWindow();
    }
});

Ext.create('Ext.panel.Panel', {
    renderTo: Ext.getBody(),
    width: 400,
    height: 300,
    items: [extSVN]
});

【问题讨论】:

  • 你在做什么来关闭窗口?
  • 将您的代码放入fiddle
  • 点击关闭图标(窗口的十字或“x”按钮)
  • 尝试将 closeAction 改为 'destroy' 而不是 'hide'。

标签: extjs extjs3


【解决方案1】:

您在窗口上使用closeAction: 'hide',这意味着当您关闭它时,它不会被破坏而是隐藏。 问题是,当您重新打开窗口时,您会创建一个新窗口,因此您的 formPanel 最终会出现在 2 个不同的窗口中,这会导致错误。

你可以:

  • 删除closeAction: 'hide',但您的formPanel 也将 关闭窗口时销毁,因此您必须重新创建 另一个也是
  • 或保留closeAction: 'hide',只创建 一次窗口

【讨论】:

    【解决方案2】:

    您已将id 提供给您的formwindow。在窗口内,您设置了配置closeAction: 'hide',这意味着每当您按下关闭按钮window 时隐藏。

    然后再次单击Checkout from SVN 按钮,您将创建相同的windowform 和相同的id's,因此您可以使用上一个窗口并再次显示,而不是创建新的window

    在这个FIDDLE中,我使用您的代码创建了一个演示并进行了一些修改。

    代码片段

    Ext.onReady(function () {
        var formPanel = new Ext.FormPanel({
            height: 125,
            autoScroll: true,
            id: 'formpanel',
            defaultType: 'field',
            frame: true,
            title: 'CheckOut from SVN',
            items: [{
                fieldLabel: 'SVN Path'
            }],
            buttons: [{
                text: 'Submit',
                minWidth: 75,
                handler: function () {
    
                    var urlTemp = './Export?' + '&' + fp.getForm().getValues(true);
                    formPanel.getForm().submit({
                        url: urlTemp,
                        method: 'Post',
                        success: successFn1,
                        timeout: 18000000,
                        failure: otherFn
                    });
                }
            }, {
                text: 'Reset',
                minWidth: 75,
                handler: function () {
                    formPanel.getForm().reset();
                }
            }]
        });
    
        function buildWindow(btn) {
            if (!btn.win) {
                btn.win = new Ext.Window({
    
                    layout: 'fit',
    
                    id: 'newWindow',
    
                    modal: true,
    
                    width: 300,
    
                    height: 200,
    
                    closeAction: 'hide',
    
                    plain: true,
    
                    stateful: false,
    
                    items: [formPanel]
                });
            }
    
            btn.win.show();
        }
    
        var extSVN = new Ext.Button({
            text: 'Checkout from SVN',
            minWidth: 75,
            handler: buildWindow
        });
    
        new Ext.Panel({
            title: 'SVN Chekcout',
            renderTo: Ext.getBody(),
            width: 200,
            height: 130,
            items: [extSVN],
            renderTo: Ext.getBody()
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多