javascript Extjs 确认框回调处理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22222292/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Extjs confirm box callback handling
提问by DarkKnightFan
In my ExtJs code I am checking the value of a warning flag.
在我的 ExtJs 代码中,我正在检查警告标志的值。
If the flag is set I want to show a confirm (OKCANCEL) box to the user where I ask the user if he wants to proceed even though there is a warning.
如果设置了标志,我想向用户显示一个确认(OKCANCEL)框,即使有警告,我也会询问用户是否要继续。
Now just like any confirm box if the user clicks OK, the code should proceed to the next command in sequence and if he clicks CANCEL the code should return.
现在就像任何确认框一样,如果用户单击“确定”,代码应该按顺序继续执行下一个命令,如果他单击“取消”,代码应该返回。
Following is my code:
以下是我的代码:
if(warning){
Ext.MessageBox.show({
title: 'Icon Support',
msg: 'Are you sure you want to proceed?',
buttons: Ext.MessageBox.OKCANCEL,
icon: Ext.MessageBox.WARNING,
fn: function(btn){
if(btn == 'ok'){
// go to the alert statement below.
} else {
return;
}
}
);
alert('wants to proceed ahead'); //if user clicks OK then come here
}
Now the problem I am facing is when the code enters the if
block it shows the message box and then it alerts wants to proceed ahead
.
现在我面临的问题是,当代码进入if
块时,它会显示消息框,然后发出警报wants to proceed ahead
。
I can stop that from happening by putting a return;
statement before the alert()
.
我可以通过return;
在alert()
.
But how do I go to the alert statement after the user clicks OK button?
但是,在用户单击“确定”按钮后如何转到警报语句?
回答by Sergey92zp
Callbacks it is event driven architecture, and JavaScript it is interpreted programming language.
回调是事件驱动架构,JavaScript 是解释性编程语言。
So the best way will be
所以最好的方法是
function SomeFunc(){
//some code
}
if(warning){
Ext.MessageBox.show({
title: 'Icon Support',
msg: 'Are you sure you want to proceed?',
buttons: Ext.MessageBox.OKCANCEL,
icon: Ext.MessageBox.WARNING,
fn: function(btn){
if(btn == 'ok'){
SomeFunc();
} else {
return;
}
}
});
}
回答by charCo
Something to note, I think your alert may just be an example of code that you are wanting to use as a placeholder for real code processing.
需要注意的是,我认为您的警报可能只是您想要用作实际代码处理的占位符的代码示例。
But just in case it's the first line of more code, a plain alert will block the processing of the browser and remove focus from the current window.
但以防万一它是更多代码的第一行,普通警报将阻止浏览器的处理并从当前窗口中移除焦点。
http://www.w3schools.com/jsref/met_win_alert.asp
http://www.w3schools.com/jsref/met_win_alert.asp
I second Sergey's reply and just had to rearrange code to correctly get callback functions in place, now that a proceed through the message was needed on "Ok". I considered the looping but that was not safe.
我第二次回复 Sergey 的回复,只需要重新排列代码以正确获取回调函数就位,现在需要在“确定”时继续处理消息。我考虑了循环,但这并不安全。