这只是一个带有单选按钮的警报框。除一件事外,其他所有工具都工作正常。也就是说,如果出现错误,我将无法保留警报框,直到用户输入正确的数据为止。根据{{3}},我使用了return false
功能。但是还没有运气。有任何线索吗?
Note:
如果输入为text boxes
,则可以正常工作。这里我需要单选按钮。
const allApiKeys = await this.apiKeySqliteProvider.getAllApiKeys();
const alert = this.alertCtrl.create();
alert.setTitle('Select Api Key');
forEach(allApiKeys, (apiKey: ApiKey) => {
alert.addInput({
type: 'radio',
label: apiKey.name,
value: apiKey.key,
checked: false
});
});
alert.addButton({
text: 'Cancel',
role: 'cancel',
handler: data => {
this.loading.dismissLoader(loading);
}
});
alert.addButton({
text: 'OK',
handler: data => {
let navTransition = alert.dismiss();
navTransition.then(() => {
if (data == null) {
this.showToastProvider.showErrorToast("Invalid API Key");
this.loading.dismissLoader(loading);
return false;
}
});
return false;
}
});
alert.present();
}
答案 0 :(得分:1)
return false
不是实际问题。您正在呼叫alert.dismiss
,这就是问题所在。如果您不想隐藏警报,则应在dismiss
块内移动else
代码。
请将您的代码更改为
const allApiKeys = await this.apiKeySqliteProvider.getAllApiKeys();
const alert = this.alertCtrl.create();
alert.setTitle('Select Api Key');
forEach(allApiKeys, (apiKey: ApiKey) => {
alert.addInput({
type: 'radio',
label: apiKey.name,
value: apiKey.key,
checked: false
});
});
alert.addButton({
text: 'Cancel',
role: 'cancel',
handler: data => {
this.loading.dismissLoader(loading);
}
});
alert.addButton({
text: 'OK',
handler: data => {
if (data == null) {
this.showToastProvider.showErrorToast("Invalid API Key");
this.loading.dismissLoader(loading);
return false;
}
// you don't need else here as by default it will hide alert
}
});
alert.present();
}