此 API 可用于显示从编辑器顶部弹出的通知。
由于这些通知会打断用户,因此应谨慎使用。
RED.notify(message, [options])
message
- 要在通知中显示的文本options
- 通知配置选项此函数返回一个 notification
对象,可用于与通知进行交互。
可在 options
参数中提供以下属性。所有属性都是可选的。
选项 | 描述 |
---|---|
类型 |
设置通知的外观。可用值有:compact 、success 、warning 、error 。如果未设置此值,通知将使用默认的“信息”外观。 |
超时 |
通知应显示的时长,以毫秒为单位。默认值:5000 。如果设置了 fixed 属性,则忽略此值。 |
固定 |
超时后不隐藏通知。这也会阻止通知的点击关闭默认行为。 |
模态 |
如果设置为 true ,通知应阻止与任何其他 UI 元素交互,直到通知被关闭。 |
按钮 |
要在通知上显示的按钮数组,以允许用户交互。 |
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() |
关闭通知并处理它。 |
notification.update( message, options ) |
替换通知的内容。 |
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();
}
}
]
});
版权所有 OpenJS Foundation 和 Node-RED 贡献者。保留所有权利。OpenJS Foundation 已注册商标并使用商标。有关 OpenJS Foundation 商标列表,请参阅我们的商标政策和商标列表。OpenJS Foundation 商标列表中未指明的商标和徽标是其各自所有者的商标™或注册®商标。使用它们并不意味着与它们有任何关联或得到它们的认可。
OpenJS Foundation | 使用条款 | 隐私政策 | OpenJS Foundation 章程 | 商标政策 | 商标列表 | Cookie 政策