node-red:在 api 响应上添加模式对话框
node-red: add a modal dialog on api response
我需要一些有关 Node Red 流程编辑器的帮助。我修改了导出节点到剪贴板模式对话框,并在 "Export to clipboard" 之后添加了一个按钮。单击按钮时,我进行了外部 API 调用,它工作正常并从服务器获得响应。调用 API 的代码写在 /api/editor/code.js 文件中,如下所示:
const { flows } = redNodes.getFlows();
axios.post(externalUrl, flows)
.then((response) => {
// nice little modal dialog on response
res.status(200).send(response.data.message);
})
.catch((error) => {
console.log('error', error.message);
});
我想在 Node Red 应用程序内的模态对话框中显示从 API 调用中获得的信息。我该如何实现?
谢谢
你有两个选择:
Node-RED 使用 jQuery UI,因此您可以创建自己的 jQuery Dialog,包含您想要的任何内容。有很多使用 api 的例子 - 我不会在这里重复它们。
Node-RED 为下拉通知提供 RED.notify
api。您可以使用它来显示结果。
最简单的方法是调用:
RED.notify("This is my message");
并且该消息将默认显示 5 秒。
如果你想让它一直坚持到用户点击按钮,你可以这样做:
var myNotification = RED.notify("This is the message to display",{
modal: true,
fixed: true,
buttons: [
{
text: "cancel",
click: function(e) {
myNotification.close();
}
},
{
text: "okay",
class:"primary",
click: function(e) {
myNotification.close();
}
}
]
});
我需要一些有关 Node Red 流程编辑器的帮助。我修改了导出节点到剪贴板模式对话框,并在 "Export to clipboard" 之后添加了一个按钮。单击按钮时,我进行了外部 API 调用,它工作正常并从服务器获得响应。调用 API 的代码写在 /api/editor/code.js 文件中,如下所示:
const { flows } = redNodes.getFlows();
axios.post(externalUrl, flows)
.then((response) => {
// nice little modal dialog on response
res.status(200).send(response.data.message);
})
.catch((error) => {
console.log('error', error.message);
});
我想在 Node Red 应用程序内的模态对话框中显示从 API 调用中获得的信息。我该如何实现?
谢谢
你有两个选择:
Node-RED 使用 jQuery UI,因此您可以创建自己的 jQuery Dialog,包含您想要的任何内容。有很多使用 api 的例子 - 我不会在这里重复它们。
Node-RED 为下拉通知提供
RED.notify
api。您可以使用它来显示结果。
最简单的方法是调用:
RED.notify("This is my message");
并且该消息将默认显示 5 秒。
如果你想让它一直坚持到用户点击按钮,你可以这样做:
var myNotification = RED.notify("This is the message to display",{
modal: true,
fixed: true,
buttons: [
{
text: "cancel",
click: function(e) {
myNotification.close();
}
},
{
text: "okay",
class:"primary",
click: function(e) {
myNotification.close();
}
}
]
});