【问题标题】:Prevent event when toastr closed with close button.使用关闭按钮关闭 toastr 时防止事件。
【发布时间】:2017-02-15 15:03:02
【问题描述】:

在我的应用程序中使用toastr.js,并且我有这样的流程,当用户提交表单时,我需要显示 toast 并给他一些时间通过单击关闭按钮来关闭此 toast 以防止向服务器发送数据,但是如果他不关闭吐司,应该发送数据。

我有这样的问题:

toastr.options = {
   closeButton: true,
   onHidden: () => { //send data to the server },
   onCloseClick: () => { console.log('you clicked close button') },
}
toastr.success('success');

问题是 onHidden 方法总是会被触发。 请帮忙!

【问题讨论】:

    标签: javascript angular toastr


    【解决方案1】:

    好心人帮帮我! 解决办法是:

           isPrevented = false;
           toastr.options = {
              closeButton: true,
              onHidden: () => {
                if (isPrevented) {
                  return false;
                } else {
                  //Sent result to server;
                }
              },
              onCloseClick: () => {
                isPrevented = true
              }
            }
    

    感谢所有贡献者! )

    【讨论】:

      猜你喜欢
      • 2016-02-10
      • 1970-01-01
      • 2012-11-24
      • 2015-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-17
      相关资源
      最近更新 更多