[英]For loop in Function node only returning the first iteration
I am trying to create a loop in a function node in Node-Red that basically acts like a countdown timer for me. 我正在尝试在Node-Red的功能节点中创建一个循环,该循环基本上对我来说就像一个倒数计时器。 Right now when I run this node I only get a single output from the node with msg.playload saying "Back in 15 minutes".
现在,当我运行该节点时,我只能从该节点得到一个带有msg.playload的输出,说“ 15分钟后返回”。
What I want is to get 15 outputs one after another that say "Back in 15 minutes", "Back in 14 minutes", ect. 我想要的是一个接一个地获得15个输出,分别是“ 15分钟后返回”,“ 14分钟后返回”等。 Once I can get that I will add in a delay so that the for loop waits for 1 minute each time it runs.
一旦获得,我将添加一个延迟,以便for循环每次运行都等待1分钟。
var totalMinutes = 15
for (var i = 0; i < 15; i++){
var minutesLeft = totalMinutes - [i];
msg.payload = {
"profile": {
"status_text": "Back in " + minutesLeft + " minutes",
"status_emoji": ":coffee:",
"status_expiration": 0
}
};
return [msg.payload];
}
return [msg];
you are stopping the code from continuing by using return [msg.payload];
您通过使用
return [msg.payload];
阻止代码继续return [msg.payload];
. 。 Remove that line and it should print out the way you want it.
删除该行,它应该以您想要的方式打印出来。
Note that the print out is not equivalent to 1 second. 请注意,打印输出不等于1秒。 To do that you can wrap in a
setInterval()
为此,您可以包装
setInterval()
checkout https://www.w3schools.com/js/js_timing.asp for more details. 查看https://www.w3schools.com/js/js_timing.asp了解更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.