如何使用 SweetAlert2 在队列链中为单个 Swal 使用 promise

如何解决如何使用 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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?