将 Id 添加到 toastr 通知

Adding Id to the toastr notification

是否可以将 Id 添加到 Toastr 通知中? 当我关闭它时,我需要确定几个通知之一。 我用这个插件。 https://github.com/CodeSeven/toastr

这是一个有趣的问题。看起来您无法在 toastr 本身上设置 ID。但是,您可以修改用于关闭toastr的按钮:

toastr.options.closeHtml = '<button id="toastr1closebtn"><i class="icon-off"></i></button>';

这可能与您正在尝试做的事情一样好。

我找到了调整关闭按钮的选项here

如果您使用 toastr.options.closeButton = true;,您可以指定一个在您关闭时应该 运行 的函数。该函数将传递点击事件。该事件可以(希望)用于确定关闭了哪个通知。

toastr.options.onCloseClick = function(event) {
  const closedElement = event.target.parentElement;
  // figure out which notfication was closed based on class, or text, or...
}

也许有更好的方法,但这是我根据 the pretty sparse documentation and some tinkering with the plunker example 他们的发现。