【问题标题】:Prevent multiple instances of toastr on same page防止在同一页面上出现多个 toastr 实例
【发布时间】:2018-07-19 08:09:43
【问题描述】:

有没有办法防止 toastr 在单个页面上显示同一消息的多个实例。我正在使用一页来满足我的添加和更新功能。这是我的代码的 sn-p

window.toastr.options = {
          "toastClass": "toast-success-create-campaign",
          "closeButton": false,
          "debug": false,
          "newestOnTop": true,
          "progressBar": false,
          "positionClass": "toast-top-center",
          "onclick": null,
          "showDuration": "300",
          "hideDuration": "1000",
          "timeOut": "5000",
          "extendedTimeOut": "1000",
          "showEasing": "swing",
          "hideEasing": "linear",
          "showMethod": "fadeIn",
          "hideMethod": "fadeOut",
          "maxOpened":1,
          "preventOpenDuplicates": true
}

$('.btn-add').on('click',function(){
  window.toastr.success('Add Called','Success!');
})

$('.btn-update').on('click',function(){
  window.toastr.success('Update Called','Success!');
})

似乎 toastr 保留了所有 toast 调用的缓存,这就是为什么当我尝试执行该函数时,它会相互叠加而不是只显示一个。如何修改我的代码以获得我想要的输出。

【问题讨论】:

    标签: jquery toastr


    【解决方案1】:

    看起来 preventOpenDuplicates 在 Toastr 的原生 JavaScript 版本上不受支持,它仅在 angular-toastr 中受支持。

    查看source code,文本Open 甚至不包含在那里。
    有一个拉取请求 (Prevent duplicate #568) 要求添加对 preventOpenDuplicates 的支持,但它没有合并,也没有评论。

    【讨论】:

      猜你喜欢
      • 2022-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多