Return Node-RED 功能块上的每个输出一条消息

Return one message for each output on Node-RED function block

在 Node-RED 中,我如何 return 功能块上的多个消息,每个输出一个?

我根据文档进行了尝试,但没有成功。

msg1 = "1"
msg2 = "2";
msg3 = "3";

msg.payload = [msg1, msg2, msg3];

return msg

您需要 return 对象而不仅仅是字符串,因此首先您需要使用有效负载键构建对象

msg1 = {payload: "1"}
msg2 = {payload: "2"};
msg3 = {payload: "3"};

msg = [msg1, msg2, msg3];

return msg;
var msg1 = { payload:"@" + msg.tweet.user.screen_name + "first out of output 1" };
var msg2 = { payload:"@" + msg.tweet.user.screen_name + "second out of output 1" };
var msg3 = { payload:"@" + msg.tweet.user.screen_name + "third out of output 1" };
var msg4 = { payload:"@" + msg.tweet.user.screen_name + "only message from output 2" };
return [ [ msg1, msg2, msg3 ], msg4 ];