上一个例子不起作用的原因很简单:您声明了msg1、msg2、msg3并为它们分配了字符串。节点red希望始终返回对象,而不是字符串。
因此,如果您替换:
var msg1 = 'a';
var msg2 = 'b';
var msg3 = 'c';
签署人:
var msg1 = {};
var msg2 = {};
var msg3 = {};
运行流时不会看到错误,但是..也许这不是你想要的。为了提供更准确的响应,有必要询问您希望在开关箱未选择的两个输出上交付什么?
一个更常见的解决方案,但不符合您的要求(使用具有多个输出的功能节点)将使用节点红色开关节点,如下流所示:
[{"id":"741aef4.6e6c91","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"5adb5fe6.46687","type":"switch","z":"741aef4.6e6c91","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"}],"checkall":"false","repair":false,"outputs":3,"x":330,"y":160,"wires":[["daac55db.1fcbc8"],["c1d473f8.3e399"],["46b134bc.88338c"]]},{"id":"51cdd5fa.e5c28c","type":"inject","z":"741aef4.6e6c91","name":"","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":120,"wires":[["5adb5fe6.46687"]]},{"id":"235d0c65.794ed4","type":"inject","z":"741aef4.6e6c91","name":"","topic":"","payload":"2","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":160,"wires":[["5adb5fe6.46687"]]},{"id":"134e5583.3f7a4a","type":"inject","z":"741aef4.6e6c91","name":"","topic":"","payload":"3","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":200,"wires":[["5adb5fe6.46687"]]},{"id":"daac55db.1fcbc8","type":"change","z":"741aef4.6e6c91","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"foo\":1,\"bar\":10}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":140,"wires":[["50f4c1a9.ea486"]]},{"id":"c1d473f8.3e399","type":"change","z":"741aef4.6e6c91","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"foo\":2,\"bar\":12}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":180,"wires":[["cad7dc88.0db57"]]},{"id":"46b134bc.88338c","type":"change","z":"741aef4.6e6c91","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"foo\":3,\"bar\":13}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":220,"wires":[["6da7761e.5c70f8"]]},{"id":"50f4c1a9.ea486","type":"debug","z":"741aef4.6e6c91","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":660,"y":140,"wires":[]},{"id":"cad7dc88.0db57","type":"debug","z":"741aef4.6e6c91","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":660,"y":180,"wires":[]},{"id":"6da7761e.5c70f8","type":"debug","z":"741aef4.6e6c91","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":660,"y":220,"wires":[]}]