Extjs:关闭窗口前保存更改的确认消息
我有一个可编辑的窗口。当用户试图关闭窗口时,我需要检查窗口中是否有任何更改。如果没有更改,窗口应关闭。如果有任何更改,我需要提示用户是否需要保存更改。如果用户说是,则将保存更改并关闭窗口,否则窗口将关闭而不进行更改。为此,我在代码的控制器层编写了代码。当用户单击窗口中的“关闭”按钮时,一切正常。但只有当用户试图通过单击窗口右上角的默认[X]来关闭窗口时,问题才会出现。我试图在用户单击该方法时调用我的方法,但由于extjs的异步特性,窗口最初关闭,然后调用该方法。我尝试使用beforeclose事件,但没有用 这是我在视图层中的一段代码。 Ext.define('MyApp.view.MyWindow'{ 扩展:“Ext.window.window”, xtype:'myDetail', itemId:'我的详细信息'Extjs:关闭窗口前保存更改的确认消息,extjs,window,confirmation,Extjs,Window,Confirmation,我有一个可编辑的窗口。当用户试图关闭窗口时,我需要检查窗口中是否有任何更改。如果没有更改,窗口应关闭。如果有任何更改,我需要提示用户是否需要保存更改。如果用户说是,则将保存更改并关闭窗口,否则窗口将关闭而不进行更改。为此,我在代码的控制器层编写了代码。当用户单击窗口中的“关闭”按钮时,一切正常。但只有当用户试图通过单击窗口右上角的默认[X]来关闭窗口时,问题才会出现。我试图在用户单击该方法时调用我的方法,但由于extjs的异步特性,窗口最初关闭,然后调用该方法。我尝试使用beforeclose事
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.confirmsaveforeclose,this);
this.on(null,'close',this.confirmsaveforeclose,this)
这里的colseBtn事件工作正常,但问题只出现在默认的windows关闭选项中
有没有人能告诉我,当用户单击[x]按钮时,如何在控件中指向该方法
谢谢..在关闭窗口上的
前收听事件并返回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;
}
}