我正在使用Extjs版本4.0.7开发项目,并且遇到问题。 我有一个功能,在保存前验证数据有效性。它看起来像这样:Extjs/Javascript - 在函数返回之前等待MessageBox响应
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
之前,其中我标有/ 问题行 /? 因为现在这个函数并没有采用我的是或否的答案,它总是返回{success: 'true'}
,这是正常的,考虑到函数结构如何。
任何想法?谢谢!
你已经显示消息框上else if(expression2),所以当消息显示时,else return {success:true};条件不会执行。 –
你说得对,我在这里错了,但在我的代码不是。 – darkdante