根据消息类型设置烤面包机选项(Aurelia)

问题描述 投票:0回答:1

尝试在此项目中设置错误类型的消息,使其淡出时间比其他类型的消息更长。我正在使用Aurelia作为框架。

我目前已将烤面包机选项设置如下:

app.js

@inject(Endpoint.of('api'), Router, FetchConfig, AppRouterConfig, AuthService, EventAggregator)
export class App {
  constructor(api, router, fetchConfig, appRouterConfig, authService, EventAggregator) {
    this.api = api;
    this.router = router;
    this.fetchConfig = fetchConfig;
    this.appRouterConfig = appRouterConfig;
    this.authService = authService;
    this.ea = EventAggregator;

    /* Define the options for the toastr messages */
    toastr.options = {
      "closeButton": true,
      "debug": false,
      "newestOnTop": false,
      "progressBar": false,
      "positionClass": "toast-top-full-width",
      "preventDuplicates": false,
      "onclick": null,
      "showDuration": "500",
      "hideDuration": "1000",
      "timeOut": "5000", // I want this to be 20000 for error-type messages ONLY
      "extendedTimeOut": "1000",
      "showEasing": "swing",
      "hideEasing": "linear",
      "showMethod": "fadeIn",
      "hideMethod": "fadeOut"
    }
  };

我正在使用Aurelia的pub / sub,以便在需要时生成烤面包机消息。我已将Toastr订阅放入App类的attach()生命周期挂钩中:

app.js

this.toastSubscription = this.ea.subscribe('toast', toast => {
  toastr[toast.type](toast.message);
});

然后,在项目中我需要使用烤面包消息的其他任何地方,我都会使用此发布:

example.js

  /* For an error */
  this.ea.publish('toast', {
    type: 'error',
    message: 'Some fancy error message',
  });

  /* For a success */
  this.ea.publish('toast', {
     type: 'success',
     message: 'Much success, very achieved, wow'
  })

我将如何设置此系统以使用具有更长衰落时间的错误类型的消息?我尝试了这个似乎没有用的方法:

app.js

  /* Modify the subscription to accept timeOut as an override of global options */
  this.toastSubscription = this.ea.subscribe('toast', toast => {
    toastr[toast.type](toast.message, {timeOut: toast.timeout});
  });

example.js

  this.ea.publish('toast', {
    type: 'error',
    message: 'Errors are love, errors are life',
    timeout: 10000 // Pass in a longer timeOut than for other messages
  });

但是以上操作均未成功。

有什么想法吗?

javascript aurelia toastr
1个回答
0
投票

您与上一个示例很接近。

 this.ea.publish('toast', {
    type: 'error',
    message: 'Errors are love, errors are life',
    timeout: 10000 // Pass in a longer timeOut than for other messages
  });

您已经将选项作为第二个参数,但它们是第三个参数。

 this.ea.publish('toast', '', {
    type: 'error',
    message: 'Errors are love, errors are life',
    timeout: 10000 // Pass in a longer timeOut than for other messages
  });

第二个参数是标题,如果您不想要标题,则保留该空白,然后将您的选项作为第三个参数

© www.soinside.com 2019 - 2024. All rights reserved.