Extjs / Javascript -在函数返回之前等待MessageBox响应

Extjs / Javascript - wait for MessageBox response before function return

本文关键字:等待 MessageBox 响应 返回 函数 Javascript Extjs      更新时间:2023-09-26

我正在做一个Extjs项目,4.0.7版,我有一个问题。我有一个在保存之前验证数据有效性的函数。它看起来像这样:

        me.validateEmployeeSystemSettingsOnSave = function (a,b,c) { 
           switch (c) {
        case 1:{
         if(expression)
           return {success: false}
           if(expression2){
           Ext.Msg.show({
                title:'',
                    msg:'',
                buttons: Ext.Msg.YESNO,
                icon: Ext.Msg.QUESTION,
                fn: function (btn) {
                if (btn == 'yes') {
                return { success: true };
                }
                else if (btn == 'no') {
                return { success: false};
                }
                },
                modal: true
                 });
             }
      else return {success: true}; /*problem line*/ //this is the default answer, when function will 
//not enter any expression and return {success: true} 
    }
    case 2:{
    }
    }

上面的函数是在onSave函数中调用的,像这样:

 var response = me.validateEmployeeSystemSettingsOnSave(dsa,ssa,daa){
   if(response.success){
this.save();
}
else{
}
}

我的问题是:是否有任何方法可以等待Ext.msg.show()的答案,在到达默认的return之前,我用/问题行/标记?因为现在函数不接受我的yes或no答案,它总是返回{success: 'true'},这是正常的,考虑到函数的结构。

任何想法?谢谢你!

你不应该等待,而是使用回调!所以在你的情况下执行回调,而不是返回{ success: true };