【问题标题】:Extjs : Confirmation message to save changes before closing a windowExtjs:在关闭窗口之前保存更改的确认消息
【发布时间】:2014-12-28 06:45:15
【问题描述】:

我有一个可编辑的窗口。当用户尝试关闭窗口时,我需要检查窗口中是否进行了任何更改。如果没有变化,窗口应该关闭。如果有任何更改,我需要提示用户是否需要保存更改。如果用户说是,更改将被保存并关闭窗口,否则窗口关闭而不进行更改。为此,我在代码的控制器层中编写了代码。当用户单击窗口中的关闭按钮时,一切都按预期正常工作。但是只有当用户尝试通过单击窗口右上角的默认 [X] 来关闭窗口时,才会出现问题。当用户单击它时,我试图调用我的方法,但由于 extjs 的异步特性,窗口最初会关闭,然后调用该方法。我尝试使用 beforeclose 事件但没有用。

这是我在视图层中的一段代码。 Ext.define('MyApp.view.MyWindow', { 扩展:'Ext.window.Window', xtype:'myDetail', itemId: 'myDetail',

requires: [        
    'ABC.controller.myDetail.myDetailController'
],

cls:'windowPopup myDetail',
title : 'ABC Detail',
layout: 'fit',
minimizable: true,
maximizable: true,
width: 1000,
height: 650,
constrain: true,
controller: null,          

initComponent: function() {
    this.items = [
        ---------------------
    ]

    this.setTitle('ABC Detail - ' + this.config.myDetail.referenceNum);

    var userNotification = '';
    var bodyStyle = 'color: #000000;'


    this.dockedItems = [{
        xtype: 'toolbar',
        dock: 'bottom',
        ui: 'footer',
        items: [
            {
                xtype: 'panel',
                html: userNotification,
                bodyStyle: bodyStyle
            }, '->',
            {
                iconCls: 'icon-save',
                cls:'blackButton',
                itemId: 'updateAndClose',
                text: 'Update & Close',
                action: 'updateClose'
            },{
                iconCls: 'icon-reset',
                cls:'blackButton',
                text: 'Update',
                action: 'update',
                itemId: 'update'
            },{
                iconCls: 'icon-reset',
                cls:'blackButton',
                itemId: 'composeEmail',
                text: 'Compose Email',
                action: 'composeEmail'
            },{
                iconCls: 'icon-reset',
                cls:'blackButton',
                text: 'Refresh',
                action: 'refresh',
                itemId: 'refresh'
            },{
                iconCls: 'icon-reset',
                text: 'Close',
                cls:'blackButton',
                scope: this,
                itemId: 'closeBtn'                  
            } 
        ]
    }];

    this.callParent(arguments);
    this.controller = Ext.create(XYZ.controller.mydetail.myDetailController', {view:this, identifier:this.identifier});

}    

});

我正在处理控制器层中的按钮,因此如果用户单击关闭按钮,则控制器将检查是否进行了任何更改,然后采取相应措施。

在控制器中,我使用的是 this.on('closeBtn', 'click', this.confirmSaveBeforeClose, this); this.on(null, 'close', this.confirmSaveBeforeClose, this);

这里 colseBtn 事件可以正常工作,但问题仅出现在默认的窗口关闭选项中。

当用户点击 [x] 按钮时,谁能告诉我如何指向控制器中的方法。

谢谢..

【问题讨论】:

    标签: extjs window confirmation


    【解决方案1】:

    收听窗口上的beforeclose 事件和return false; 以取消它。存储一些你已经阻止关闭的变量,所以下次你点击它时,清除参数。比如:

    listeners: {
        beforeclose: function(w) {
            if (!w.pendingClose) {
                w.pendingClose = true;
                Ext.Msg.confirm('Foo', 'Bar', function(btn) {
                    if (btn === 'yes') {
                        w.close();
                    } else {
                        delete w.pendingClose;
                    }
                });
                return false;
            } 
            delete window.pendingClose;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-06
      • 1970-01-01
      • 2017-11-14
      • 2023-02-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多