提问人:Daniel 提问时间:10/25/2023 最后编辑:hardillbDaniel 更新时间:10/27/2023 访问量:92
节点 RED 中的日期选取器范围
Datepicker Range in Node RED
问:
我目前正在使用 Node RED,并想制作一个 Datepicker Range。 我的目标是:
使用两个“Datepicker”节点中的两个选定日期来显示我的数据库中的特定时间间隔。
这是我的 JSON 代码流程:
(请注意,您需要安装“node-red-contrib-postgresql”和“node-red-dashboard”)
[
{
"id": "df8b8a9806f4a546",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": "",
"env": []
},
{
"id": "0623165a65c01c00",
"type": "function",
"z": "df8b8a9806f4a546",
"name": "Processing Datepicker Output",
"func": "if (msg.topic === \"Datepicker_Von\") {\n // Hier verarbeiten Sie den Wert des ersten Datepicker-Node\n var date1 = msg.payload;\n // Führen Sie weitere Verarbeitungen für Datepicker1 durch\n} else if (msg.topic === \"Datepicker_Bis\") {\n // Hier verarbeiten Sie den Wert des zweiten Datepicker-Node\n var date2 = msg.payload;\n // Führen Sie weitere Verarbeitungen für Datepicker2 durch\n}\n\nmsg.params = [date1, date2];\n\n\n/*\nvar date1 = msg.payload[0].Datepicker_Von;\nvar date2 = msg.payload[1].selectedDate;\n\nif(date1 && date2){\n msg.payload = {date1, date2};\n return msg;\n\n}\n*/",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 870,
"y": 780,
"wires": [
[
"5ca2e58ccda4292e",
"5dbeae4a01d86c01"
]
]
},
{
"id": "35a5189090d65418",
"type": "postgresql",
"z": "df8b8a9806f4a546",
"name": "Abfrage_Kalender",
"query": "SELECT wert, datum_m\nFROM alle.aggregatparameterwerte1min\nWHERE DATE(datum_m) BETWEEN $1 AND $2\n",
"postgreSQLConfig": "7a4e4f0f64750523",
"split": false,
"rowsPerMsg": 1,
"outputs": 1,
"x": 1410,
"y": 780,
"wires": [
[
"c7ef1139c1942183"
]
]
},
{
"id": "c7ef1139c1942183",
"type": "debug",
"z": "df8b8a9806f4a546",
"name": "debug 10",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1740,
"y": 780,
"wires": []
},
{
"id": "5ca2e58ccda4292e",
"type": "debug",
"z": "df8b8a9806f4a546",
"name": "debug 11",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1200,
"y": 940,
"wires": []
},
{
"id": "1c2689ab7eb8477d",
"type": "debug",
"z": "df8b8a9806f4a546",
"name": "debug 12",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 780,
"y": 480,
"wires": []
},
{
"id": "5906020c8eecbd4b",
"type": "debug",
"z": "df8b8a9806f4a546",
"name": "debug 13",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 700,
"y": 1040,
"wires": []
},
{
"id": "95076555af56bb28",
"type": "ui_date_picker",
"z": "df8b8a9806f4a546",
"name": "",
"label": "Datepicker 2",
"group": "c69e5a41.8b69a8",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"topic": "Datepicker_Bis",
"topicType": "str",
"className": "",
"x": 510,
"y": 900,
"wires": [
[
"5906020c8eecbd4b",
"0623165a65c01c00"
]
]
},
{
"id": "981a649d06af8b02",
"type": "ui_date_picker",
"z": "df8b8a9806f4a546",
"name": "",
"label": "Datepicker 1",
"group": "c69e5a41.8b69a8",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"topic": "Datepicker_Von",
"topicType": "str",
"className": "",
"x": 510,
"y": 620,
"wires": [
[
"1c2689ab7eb8477d",
"0623165a65c01c00"
]
]
},
{
"id": "5dbeae4a01d86c01",
"type": "ui_button",
"z": "df8b8a9806f4a546",
"name": "",
"group": "c69e5a41.8b69a8",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"label": "button",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "",
"payloadType": "str",
"topic": "Datepicker_Von",
"topicType": "msg",
"x": 1150,
"y": 780,
"wires": [
[
"35a5189090d65418"
]
]
},
{
"id": "7a4e4f0f64750523",
"type": "postgreSQLConfig",
"name": "",
"host": "127.0.0.1",
"hostFieldType": "str",
"port": "5432",
"portFieldType": "num",
"database": "dme_lokal",
"databaseFieldType": "str",
"ssl": "false",
"sslFieldType": "bool",
"applicationName": "",
"applicationNameType": "str",
"max": "10",
"maxFieldType": "num",
"idle": "1000",
"idleFieldType": "num",
"connectionTimeout": "10000",
"connectionTimeoutFieldType": "num",
"user": "umeadmin",
"userFieldType": "str",
"password": "umewp1",
"passwordFieldType": "str"
},
{
"id": "c69e5a41.8b69a8",
"type": "ui_group",
"name": "Default",
"tab": "1013c4a0.9de38c",
"order": 1,
"disp": true,
"width": "6",
"collapse": false,
"className": ""
},
{
"id": "1013c4a0.9de38c",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"order": 1,
"disabled": false,
"hidden": false
}
]
如您所见,我尝试将两个“Datepicker”节点与“Function”节点连接起来。 问题是“函数”节点不会同时接收两个日期。此处发布的流程是我尝试过但失败的最新变体。
答:
1赞
hardillb
10/25/2023
#1
您需要查看连接节点,将其放在函数节点之前,并将其配置为在发送连接结果之前等待 2 个输入。
评论
0赞
hardillb
10/26/2023
您应该能够为每个日期选取器输入配置不同的值topic
0赞
Daniel
10/26/2023
这:(行不通。它说:“消息缺少键属性'msg.topic' - 无法添加对象”。我尝试将两个日期选择器的主题设置为“日期”。我尝试将它们设置为字符串和消息,但两者都不起作用。在“Join”节点中,我将值设置为 msg.topic,并且只有在给定两个值时才应发送。
0赞
Daniel
10/27/2023
感谢您的帮助!在我尝试了一些事情之后,它与“Join”节点一起使用:D
1赞
Daniel
10/26/2023
#2
是的,它奏效了!但是有一个小细节需要注意。 在每个“Datepicker”节点的主题区域中,您需要用“/”来区分主题
例:
Datepicker1 的主题:datepicker/1
Datepicker2 的主题:datepicker/2
另外需要注意的是,日期选择器的两个主题都需要采用“字符串”格式
这是名为“Datepicker 1”的 “Datepicker” 节点的 config-Tab 将完全相同的内容写入第二个日期选择器,但将所有“1”替换为“2”
如果其他人想自己尝试,这里是JSON代码:D
[
{
"id": "1c2689ab7eb8477d",
"type": "debug",
"z": "df8b8a9806f4a546",
"name": "debug 12",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 600,
"y": 600,
"wires": []
},
{
"id": "5906020c8eecbd4b",
"type": "debug",
"z": "df8b8a9806f4a546",
"name": "debug 13",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 580,
"y": 980,
"wires": []
},
{
"id": "95076555af56bb28",
"type": "ui_date_picker",
"z": "df8b8a9806f4a546",
"name": "",
"label": "Datepicker 2",
"group": "c69e5a41.8b69a8",
"order": 2,
"width": 0,
"height": 0,
"passthru": true,
"topic": "datepicker/2",
"topicType": "str",
"className": "",
"x": 290,
"y": 840,
"wires": [
[
"5906020c8eecbd4b",
"e1839d533034eac0"
]
]
},
{
"id": "981a649d06af8b02",
"type": "ui_date_picker",
"z": "df8b8a9806f4a546",
"name": "",
"label": "Datepicker 1",
"group": "c69e5a41.8b69a8",
"order": 1,
"width": 0,
"height": 0,
"passthru": false,
"topic": "datepicker/1",
"topicType": "str",
"className": "",
"x": 290,
"y": 660,
"wires": [
[
"1c2689ab7eb8477d",
"e1839d533034eac0"
]
]
},
{
"id": "e1839d533034eac0",
"type": "join",
"z": "df8b8a9806f4a546",
"name": "Datum_Vereinen",
"mode": "custom",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "2",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 630,
"y": 760,
"wires": [
[
"39fa5e85975fab78"
]
]
},
{
"id": "39fa5e85975fab78",
"type": "debug",
"z": "df8b8a9806f4a546",
"name": "debug 15",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 860,
"y": 760,
"wires": []
},
{
"id": "c69e5a41.8b69a8",
"type": "ui_group",
"name": "Default",
"tab": "1013c4a0.9de38c",
"order": 1,
"disp": true,
"width": "6",
"collapse": false,
"className": ""
},
{
"id": "1013c4a0.9de38c",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"order": 1,
"disabled": false,
"hidden": false
}
]
谢谢你对我的帮助!:D
评论