该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");
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();
}
}
]
});
Node-RED: 面向事件驱动应用的低代码编程平台。
版权所有 OpenJS基金会 及 Node-RED 贡献者。保留所有权利。OpenJS基金会 拥有注册商标并使用商标。有关 OpenJS基金会 的商标列表,请参阅我们的 商标政策 和 商标列表。未在 OpenJS基金会商标列表 中标注的商标™或注册®商标归其各自持有人所有。使用这些商标并不意味着与它们有任何关联或获得其认可。
The OpenJS Foundation | 使用条款 | 隐私政策 | OpenJS基金会章程 | 商标政策 | 商标列表 | Cookie政策