节点 RED 中的日期选择器范围

问题描述 投票:0回答:2

我目前正在使用 Node RED,想要制作一个日期选择器范围。 我的目标是:

使用两个“日期选择器”节点中选定的两个日期来显示我的数据库中的特定时间间隔。

这是我的 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”节点连接起来。
问题是“函数”节点没有同时接收两个日期。此处发布的流程是我尝试过但失败的最新变体。

Here a overview of my flow:

您需要查看连接节点,将其放置在功能节点之前,并将其配置为等待 2 个输入,然后再发送连接结果。

javascript datepicker nodes node-red date-range
2个回答
0
投票

是的,它起作用了!但有一个小细节需要注意。 在每个“Datepicker”节点的主题区域中,您需要用“/”来区分主题


0
投票

日期选择器1的主题:

datepicker/1

Datepicker2主题:

datepicker/2

还需要注意的是,日期选择器的两个主题都需要采用“字符串”格式

这里是“Datepicker”节点的配置选项卡,名称为“Datepicker 1” 将完全相同的内容写入第二个日期选择器,但将所有“1”替换为“2”

如果其他人想自己尝试一下,这里是 JSON 代码:DDatepicker 1 [ { "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

© www.soinside.com 2019 - 2024. All rights reserved.