ExtJS 4:模式窗口上的消息确认框存在问题
我目前面临一个问题,对于ExtJS或JavaScript用户来说,这似乎是一个非常常见的问题。由于消息确认框的异步性质,我面临一个问题。我在很多论坛上都试图找到解决方案,但是没有一个解决方案没有给我一个更简单的方法来处理下面的问题。或者可能是我没有理解那些暗示 下面是mycode:ExtJS 4:模式窗口上的消息确认框存在问题,extjs,extjs4,extjs4.1,Extjs,Extjs4,Extjs4.1,我目前面临一个问题,对于ExtJS或JavaScript用户来说,这似乎是一个非常常见的问题。由于消息确认框的异步性质,我面临一个问题。我在很多论坛上都试图找到解决方案,但是没有一个解决方案没有给我一个更简单的方法来处理下面的问题。或者可能是我没有理解那些暗示 下面是mycode: var modalWindow = new Ext.Window({ id: 'modalWindow', ... ... listeners: {
var modalWindow = new Ext.Window({
id: 'modalWindow',
...
...
listeners: {
beforeclose: function ( window, eOpts ){
if ( dirtyCheck() ){
//perform abc()
// and don't close the modal window
return false;
}
else {
//perform xyz()
// close the modal window
return true;
}
},
close: function ( panel, eOpts ){
//will trigger beforeclose event to check if all is well
//refresh screen
}
},
buttons: [{
text: 'Close',
handler: function () {
modalWindow.close() // Same close() method is called when we click on window close ( X symbol ) tool.
}
}]
});
function dirtyCheck(){
// Code to check if dirty records exist
if ( /* Found dirty records */ ){
Ext.MessageBox.confirm('Please Confirm', 'Changes not saved. Do you want to close the window?', function (btn) {
if (btn === 'yes') {
console.log('*** clicked yes ****');
window.close();
}
});
}
}
案例描述:我有一个网格,双击网格行打开一个上面编码的模式窗口。我对模式窗口进行了一些修改。如果用户单击“关闭”按钮或模式窗口关闭工具(右上角的X符号)或ESC按钮,我应该提示确认消息。如果用户单击“是”,我应该关闭模式窗口,否则将其保持打开状态
我了解到,单击X(关闭工具)或ESC按钮会触发“关闭”事件,该事件依次触发“beforeclose”,并等待true/false以销毁模式窗口或保持其打开
问题:当用户单击X(close tol)或ESC按钮时,当我调试时,我看到控件将在关闭前关闭,然后是我编写的dirtyCheck()函数。dirtyCheck函数也会显示一个消息确认框,但控件不会等待我单击Yes/No。它会在后台返回到beforeclose,然后再关闭。因此,当用户决定单击“是”或“否”时,ExtJS已经决定如何处理模式窗口,因此我无法控制是否关闭模式窗口
在这种情况下,有人能帮我做些什么吗?将窗口传递给您的检查功能,并在用户做出选择后将其关闭
var modalWindow = new Ext.Window({
id: 'modalWindow',
...
...
listeners: {
beforeclose: function ( window, eOpts ){
dirtyCheck(window);
return false;
},
close: function ( panel, eOpts ){
//will trigger beforeclose event to check if all is well
//refresh screen
}
},
buttons: [{
text: 'Close',
handler: function () {
modalWindow.close() // Same close() method is called when we click on window close ( X symbol ) tool.
}
}]
});
function dirtyCheck(window){
// Code to check if dirty records exist
Ext.MessageBox.confirm('Please Confirm', 'Changes not saved. Do you want to close the window?', function (btn) {
confirmation = true;
if (btn === 'yes') {
console.log('*** clicked yes ****');
window.close();
}
});
}
顺便说一句,您可以使用自己的方式,但是您需要使用本机浏览器对话框,请参阅确认函数您可能需要使用window.destroy()在确认后删除它,您的beforeClose函数可以
beforeclose: function(window, eOpts) {
Ext.Msg.confirm('Please Confirm', 'Changes not saved. Do you want to close the window?', function(answer) {
if (answer == "yes") {
window.destroy();
}
});
return false;
}
编辑您的代码解决方案(错误),而不是编辑我的原始代码段。很抱歉。说到你提供的解决方案,我发现了一个问题。让我知道我是否正确:当您在消息确认中说window.close()时,它不会触发beforeclose()事件吗?然后可能会持续循环?可能我不能直接应用你的建议。但我似乎可以通过利用close()和destroy()事件的差异找到解决问题的方法。很快会更新你的。修好了,伙计。谢谢你的主意。实际上,我在不同的地方使用了close()和destroy()的组合,并使其工作。我有相同的问题,但我找不到以下问题的解决方案。请让它进入平面,您对这个问题做了什么?我希望我能立即找到解决方案。给我一个时间之前,我得到的调整,我用粘贴在这里。