javascript - 屏幕上有多个通知时,关闭通知将关闭最后一个通知

标签 javascript jquery noty

我正在使用NOTY (通知库)版本3.0.0显示来自 JavaScript 的通知弹出窗口。

虽然屏幕上有多个通知,但当我单击关闭按钮时,它始终会关闭屏幕上放置的最后一个通知。我知道这是因为变量 n 总是被示例代码中的最后一个通知对象覆盖。但是,我在文档中没有找到有关如何在多个通知的情况下处理通知关闭的任何线索。

我应该创建一个通知对象数组,然后像 n[i].close() 这样调用 .close() 函数,还是有更好的方法来实现这一点? 请帮忙。

示例代码:

var n = new Noty({
    type: 'success',
    layout: 'bottomRight',
    theme: 'relax',
    text: "<b>Testing 2<br/><br/> ",
    timeout: false,
    closeWith: ['button'],
    animation: {
        open: 'noty_effects_open',
        close: 'noty_effects_close'
    },
    buttons: [
        Noty.button('CLOSE', 'btn btn-error', function () {
            console.log('button 2 clicked');
            n.close();
        })
      ],
}).show();

最佳答案

我认为您可以使用queue功能,您可以将多个对象推送到队列变量,并可以使用下面的示例来操作这些对象

Noty.closeAll(); // Closes all notifications
Noty.closeAll('myCustomQueueName'); // Closes all notifications with queue named 'myCustomQueueName'

Noty.setMaxVisible(10); // Sets the maxVisible notification count for global queue;
Noty.setMaxVisible(10, 'myCustomQueueName'); // Sets the maxVisible notification count for 'myCustomQueueName' queue;

关于javascript - 屏幕上有多个通知时,关闭通知将关闭最后一个通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44638698/

相关文章:

javascript - Electron,在按钮单击时创建主窗口的副本

javascript - 使noty通知成为可点击的超链接

javascript - 将 resx 编译为 Javascript

javascript - 更新Jquery中li的标题属性

javascript - 检查 if 语句中的两个条件,即使第一个条件为假

javascript - XML 样式不显示

typescript - 在 Aurelia/Typescript 应用程序中使用 noty

javascript - React$Element 和 ReactElement 有什么区别

javascript - Angular-fullstack 获取当前用户 ID