我有一个可编辑的窗口。当用户试图关闭窗口时,我需要检查是否在窗口中进行了任何更改。如果没有变化,窗口应该关闭。如果有任何更改,我需要提示用户是否需要保存更改。如果用户说是,则更改将被保存,并且窗口关闭,否则窗口关闭而不进行更改。为此,我在代码的控制器层中编写了我的代码。当用户点击窗口中的关闭按钮时,一切都按预期正常工作。但只有当用户试图通过单击窗口右上角的默认[X]来关闭窗口时才会出现问题。我试图在用户点击时调用我的方法,但由于extjs的异步性质,窗口最初关闭,然后调用方法。我尝试使用beforeclose事件,但没用。Extjs:在关闭窗口之前保存更改的确认消息
这是我在视图层的一段代码。 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); (null,'close',this.confirmSaveBeforeClose,this);
这里colseBtn事件工作正常,但问题只与默认窗口关闭选项。
有人可以给我一个想法,当用户单击[x]按钮时,如何指向控制器中的方法。
谢谢..