简体   繁体   中英

Using timeouts with toastr

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.

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);

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"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM