如何为toastr.js通知分配ID并根据需要进行更新 [英] How to assign ID to toastr.js notification and update it as needed

查看:93
本文介绍了如何为toastr.js通知分配ID并根据需要进行更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我需要保持通知打开,除非用户点击它,如果触发它和用户点击它之间的时间有更新,我需要更新吐司通知的值。

In my project I need to keep notification open unless user clicks on it and if there is an update in the time between it was triggerred and the user clicks on it, i need to update the value on the toast notificaiton.

我没有找到关于如何更新通知的任何参考。有谁知道?

I don't find any reference on how can i update a notification. Does anyone know ?

我正在使用这个github回购: toastr.js

i'm using this github repo : toastr.js

请建议

推荐答案

你通过使用在全局范围内设置 timeOut 0 ,可以无限期地保持吐司无法打开toast.options

You can keep the toast open indefinitely by setting a timeOut value of 0 on the global scope using toast.options.

或者,您可以使用toast方法的第三个参数进行设置。

Alternately, you can set it using the third argument of the toast method.

例如:

toastr.success(message body,title ,{timeOut:0})

对于第二个问题,您可以通过在创建现有吐司时捕获它的参考来更新现有吐司,并且然后在创建后改变它。

For your second question, you can update an existing toast by capturing it's reference when it's created, and then mutating it after creation.

例如:

var myToast = toastr.success("message body", "title", {timeOut:0});
myToast.find(".toast-title").text("new title");
myToast.find(".toast-message").text("new message");

您可能还想设置 extendedTimeOut 0 也是如此,以防用户在完成之前将其悬停在吐司上,如下所示:

You may also want to set the extendedTimeOut to 0 too, in case the user hovers over the toast before you've finished with it, like so:

var myToast = toastr.success("message body", "title", {timeOut:0, extendedTimeOut:0});

当你完成后,你可以通过编程方式隐藏吐司:

Then when you're done you can hide the toast programmatically:

$(myToast).fadeOut();

这篇关于如何为toastr.js通知分配ID并根据需要进行更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆