javascript - node-red 表节点
问题描述
我有一个函数,它从仪表板文本输入中获取输入作为时间选择,它计算小时和分钟,它设置其他变量并将 msg 对象返回到 Schedex 节点,但是当流是时它没有设置时间或其他变量执行。我多次修改文档并按照我的最佳理解进行操作,但它仍然没有配置我的 Schedex 节点。Schedex 文档中提到了将配置发送到 Schedex 节点的两种方式,第一种方式是设置 msg.palyload.variable 或将所有配置作为一个字符串发送到 mgs.payload 我将在下面发布两个版本的功能代码。如果您想阅读 Schedex 的文档,可以在下面找到https://www.npmjs.com/package/node-red-contrib-schedex
msgTemp = msg.payload;
time = msgTemp / 1000;
// calculates hour from seconds input
h = Math.floor(time / 3600);
// calculates minutes from remainder
m = Math.floor(time % 3600 / 60);
// ontime formatted for Schedex standards
ontime = ('0' + h).slice(-2) + ":" + ('0' + m).slice(-2);
//setting ontime
msg.payload.ontime = ontime;
//setting onpayload
msg.payload.onpayload = "1";
//enabling schedule for every time of the week
msg.payload.mon = true;
msg.payload.tue = true;
msg.payload.wed = true;
msg.payload.thu = true;
msg.payload.fri = true;
msg.payload.sat = true;
msg.payload.sun = true;
//the documentations mentions that to set the variables from the ui
//it has to be in programmatic control, I have put this in the
//payload and it's not working.
//i think my issue is with the line below but i can't figure it out
msg.payload = "'## Programmatic Control";
return msg;
这是另一个版本,其中所有配置都作为一个字符串存储在 msg.payload 上
msgTemp = msg.payload;
time = msgTemp / 1000;
// calculates hour from seconds input
h = Math.floor(time / 3600);
// calculates minutes from remainder
m = Math.floor(time % 3600 / 60);
ontime = "onetime " + ('0' + h).slice(-2) + ":" + ('0' + m).slice(-2)
+ " ";
onpayload = "onpayload 1 ";
mon = "mon true ";
tue = "tue true ";
wed = "wed true ";
thu = "thu true ";
fri = "fri true ";
sat = "sat true ";
sun = "sun true ";
msg.payload = ontime + onpayload + mon + tue + wed + thu + fri + sat
+ sun;
return msg;
非常感谢您的帮助
解决方案
第一个示例前面的最后一行通过用字符串替换该对象return
来消除您对对象所做的所有更改msg.payload
"'## Programmatic Control"
推荐阅读
- html - 如何使缩略图标题也响应?
- java - 我怎样才能用 jaxb 进行多个包装?
- java - Java 日历 NextEvent 方法
- d3.js - 更新 D3 (v6) 散点图不会添加新圆圈
- java - 带有对象列表的地图的杰克逊反序列化
- azure-devops - 在使用新图像更新 ACR 时创建触发管道的事件
- angular - 尝试使用 APP_INITIALIZER 注入器引导时没有 configService 提供程序
- java - 是否可以通过排除随附的 JIT 来使用 openjdk?
- javascript - JSON.parse 中的 SyntaxError - ReactJS
- python-3.x - 创建一个类装饰器,该装饰器本身就是一个类