RED.notify

该API可用于显示从编辑器顶部弹出的通知。

由于这些通知会打断用户,应谨慎使用。

RED.notify(message, [options])

  • message - 要在通知中显示的文本
  • options - 通知的配置选项

该函数返回一个notification对象,可用于与通知进行交互。

配置选项

以下属性可以在options参数中提供。所有属性都是可选的。

选项 描述
type Sets the appearance of the notification. Available values are: compact, success, warning, error. If this value is not set, the notification uses the default ‘info’ appearance.
timeout How long the notification should be shown for, in milliseconds. Default: 5000. This is ignored if the fixed property is set.
fixed Do not hide the notification after a timeout. This also prevents the click-to-close default behaviour of the notification.
modal If set to true, the notification should prevent interaction with any other UI element until the notification has been dismissed.
buttons An array of buttons to display on the notification to allow user interaction.

通知按钮

buttons 选项可用于提供一组应显示在通知上的按钮。

例如,要设置一个“取消”和一个“确定”按钮,可以使用以下代码(下方有更完整的示例解释myNotification.close())。

buttons: [
    {
        text: "cancel",
        click: function(e) {
            myNotification.close();
        }
    },
    {
        text: "okay",
        class:"primary",
        click: function(e) {
            myNotification.close();
        }
    }

class属性可用于为按钮指定额外的CSS类。如果通知包含多个按钮,应有一个按钮的类设置为primary,以指示用户应点击的主要按钮。

通知对象

RED.notify() 调用会返回一个 notification 对象。该对象提供以下函数:

功能 描述
notification.close() Close the notification and dispose of it.
notification.update( message, options ) Replace the contents of the notification.

示例

普通信息通知

RED.notify("Hello World");

10秒警告通知

RED.notify("Something has happened", { type: "warning", timeout: 10000 });

带按钮的通知

此示例展示了返回的myNotification对象如何在按钮事件处理程序中被用来关闭通知。

let myNotification = RED.notify("This is the message to display",{
    modal: true,
    fixed: true,
    type: 'warning',
    buttons: [
        {
            text: "cancel",
            click: function(e) {
                myNotification.close();
            }
        },
        {
            text: "okay",
            class:"primary",
            click: function(e) {
                myNotification.close();
            }
        }
    ]
});