Using timeouts with toastr

2019-09-04 07:24发布

问题:

Most of the toastr demos are client side only.

If I get a server push of this json data

   [
    {"msg": "Mortgage bill paid", "t": "i"}
    {"msg": "Account Balance below $3000", "t": "i"}
    {"msg": "Received Car payment request", "t": "w"}
    ]

How would I use toastr read through items and publish 'info' for 1 and 2, "warning" for 3, lower right is ok. I would like a delay of 2000 between toasts so the toast dont come at the same time.

Can you point me to example that show something similar. Can toastr do this. Timed messaging in a sense.

回答1:

You could loop through the array and call toastr['info'] or toastr['warning'] (map the i to info, for example). FOr delays, you could use a timeout and delay the messages by 2000 ms for each.

timeout(toastr['info']('your message'), 2000);


回答2:

This is the exact thing you need I guess

setTimeout((function() {
   toastr.info('MESSAGE TITLE', 'message content', {options});
}), delay);

toastr.options = {
  "closeButton": true,
  "debug": false,
  "newestOnTop": false,
  "progressBar": false,
  "positionClass": "toast-top-center",
  "preventDuplicates": false,
  "onclick": null,
  "showDuration": "300",
  "hideDuration": "1000",
  "timeOut": "5000",
  "extendedTimeOut": "1000",
  "showEasing": "swing",
  "hideEasing": "linear",
  "showMethod": "fadeIn",
  "hideMethod": "fadeOut"
}