javascript - 即使延迟设置为 0,Bootstrap Notify 也会自动关闭

标签 javascript twitter-bootstrap bootstrap-notify

我正在尝试让 Bootstrap Notify 警报保持可见,直到用户将其关闭,而不是自动关闭。为此,根据我对文档的理解,我将 delay 设置设置为 0。这是我的 JS 文件,包含在 bootstrap-notify.js 之后:

$(function () {
    var alertTemplate = $("#notify-template").html();
    $.notifyDefaults({ target: "_self" }, { type: "warning", delay: 0, template: alertTemplate });
});

var toasterNotify = function (alertTitle, alertMessage, alertUrl) {
    alertUrl = alertUrl || "#";
    $.notify({ title: alertTitle, message: alertMessage, url: alertUrl }, { delay: 0 });
}

当我直接从 View 中按钮上的 click 事件调用它时,这个 toasterNotify 函数完全按预期工作,但是当它从 SignalR 回调调用时服务器,如下所示,警报一出现几乎立即关闭:

var hubProxy = $.connection.applicationHub;
hubProxy.client.alertNewClaim = function (model) {
    toasterNotify(model.SourceFullName, model.Message);
};

编辑:

我发现所涉及的 Controller 操作会在返回 View 结果之前将 SignalR 消息推送到客户端。因此,客户端立即收到 SignalR 消息并显示警报,只是让返回的 View 刷新页面,快速删除警报。我仍然不知道如何解决这个问题。

最佳答案

我的 hacky 解决方法是在 Controller 端将消息发送到数据库之前将其排入队列,然后让客户端在每次加载页面时查询未标记为“已关闭”的消息。因此,用户将永远在他们访问的每个页面上看到该消息,直到他们单击消息上的“关闭”按钮,这导致请求被发送到 Messaging Controller 以标记该消息作为“解雇”。

关于javascript - 即使延迟设置为 0,Bootstrap Notify 也会自动关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32932068/

相关文章:

javascript - ORACLE APEX 5.0 中表格形式的动态计算和验证

javascript - 如何编写条件 - 如果当前日期和时间在 11 月最后一天之前 :59

html - 较小屏幕上的 Bootstrap 布局

javascript - bootstrap-growl 在 while 循环中不起作用

javascript - document.getElementById(variable) 帮助!

javascript - 从 Angular 模态服务中的模态体模板返回数据

css - 水平居中 bootstrap 3 个选项卡

android - Bootstrap 3 响应不适用于 android internet explorer 的移动设备

javascript - Rails 下使用 webpacker 进行 Bootstrap-notify 返回 $.notify 不是一个函数