开发者

Dealing with message box asynchronious

There is a function that returns true/false only after a button on messageBox is clicked dealing with extjs messagebox asynchronious.

function mayGo(){
var clicked=false;
var may=false;

        Ext.Msg.show({
            title:'del?',
            msg: 'the items will be deleted?',
            buttons: Ext.Msg.YESNO,
            fn: function (button){
                    if (button=='yes'){clicked=true;may=true;}
                    if (button=='no'){clicked=true;may=false;}
                }
        });

        newf();
        function wait(){
alert("alert2");
                var t=setTimeout(newf(), 5000);


        }
        function newf(){
            if (!clicked){alert("alert1");wait();}
        }
        return may;}

The function continues executing. What is wrong?开发者_高级运维 Why the timeout doesn't work?


remove parens from

var t=setTimeout(newf(), 5000);

so you get:

var t=setTimeout(newf, 5000);

newf was executed, so you where actually setting a timeout on the return value of newf. It was equivalent to:

var und = newf(); // returns undefined
var t = setTimeout( und , 5000 ); // wont work.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜