最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Extjs confirm box callback handling - Stack Overflow

programmeradmin0浏览0评论

In my ExtJs code I am checking the value of a warning flag.

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.

Now just like any confirm box if the user clicks OK, the code should proceed to the next mand 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 e 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.

I can stop that from happening by putting a return; statement before the alert().

But how do I go to the alert statement after the user clicks OK button?

In my ExtJs code I am checking the value of a warning flag.

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.

Now just like any confirm box if the user clicks OK, the code should proceed to the next mand 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 e 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.

I can stop that from happening by putting a return; statement before the alert().

But how do I go to the alert statement after the user clicks OK button?

Share Improve this question asked Mar 6, 2014 at 10:53 DarkKnightFanDarkKnightFan 1,95314 gold badges42 silver badges61 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Callbacks it is event driven architecture, and JavaScript it is interpreted programming language.

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;
            }
        }
    });
} 

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./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.

发布评论

评论列表(0)

  1. 暂无评论