MessageBox shown after function is over

跟風遠走 提交于 2020-01-16 04:07:12

问题


I have a javascript function that calls my javascript function, my func islike this:

function sugParitValidation(){
   var isValid = false;
   Ext.MessageBox.confirm('  ','Are you sure you want to do this?',  function(btn){
      if(btn == 'yes'){
      isValid = true;
    }
 });
 return isValid ;
}

My problem is - if statement and the return statment is happening, and only after that the confirm window being shown. That way I can't react to what the user choosed. how to solve this? tried allready use setTimeOut, no change at all....


回答1:


i think you are trying to do something like this.

someFunction(){
     if(sugParitValidation()){
          //todo something
     }
     else{
          //todo another thing
     }

}

you can do this easyly with callbacks. This is the example.

someFunction(){
     var messageCallback = function(btn){
          if(btn === 'yes'){
               //todo something
          }
          else{
              //todo another thing
          }

     }
     Ext.MessageBox.confirm('  ','Are you sure you want to do this?', 
     messageCallback);
}


来源:https://stackoverflow.com/questions/33411085/messagebox-shown-after-function-is-over

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!