如何解决如何使用 SweetAlert2 在队列链中为单个 Swal 使用 promise
我正在尝试使用 SweetAlert2 链接多个确认对话。
实际上所有的对话都是相互独立的,应该一个接一个地打开。对于每个确认对话,我希望能够处理一个单独的承诺。
在我看到的一个例子中,可以添加一个全局的 .then() 来处理 Swal.queue() 的承诺。但这对我还没有帮助,因为我根据条件添加了队列项。
此外,当其中一个 Swals 被确认时,我不希望队列中的其他人再被打开。
目前我尝试使用 Swal.queue() 来实现这一点:
let modals = [];
let modalStopGame = {
title: "Stop game?",icon: "warning",buttons: true,dangerMode: true,showCancelButton: true,cancelButtonText: "Abbrechen",confirmButtonText: "Stoppen",preConfirm: willStopGame => {
if (willStopGame) {
stopGame(bookingId);
return true;
}
},};
modals.push(modalStopGame);
let modalDeleteBooking = {
title: "Delete booking?",confirmButtonText: "Löschen",isConfirmed: willDelete => {
if (willDelete) {
deleteBooking(bookingId,"");
return true;
}
},};
modals.push(modalDeleteBooking);
swal.queue(modals);
但是有更简单的方法吗? 我想像这里看到的那样使用它,但是只有最后一个声明的 Swal 被打开。之前代码中出现的那些会被忽略...
swal({
title: "Stop game?",}).then((willStopGame) => {
if (willStopGame) {
stopGame(bookingId);
return true;
}
});
swal({
title: "Löschen der ganzen Serie?",icon: "question",}).then((willDeleteSeries) => {
if (willDeleteSeries) {
deleteBooking(bookingId,seriesId);
return true;
}
});
非常感谢, 舒尔坎2
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。