我有2个节点,需要调用一个函数 - 它在编程中很常见。
我想,在节点红色中没有办法调用该函数,除了"接线"功能节点顺序。
嗯,我确实尝试过,但没有成功。
请在我的流程中查看(copy_paste)并提供帮助:
[{"id":"d86b4b3b.0670d8","type":"inject","z":"901492e5.e9666","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":169,"y":224,"wires":[["1a6b10c8.0788cf"]]},{"id":"1a6b10c8.0788cf","type":"function","z":"901492e5.e9666","name":"func0","func":"if(msg.payload.second_call){return [null,msg];}\nelse {msg.payload[\"second_call\"] = true;\nmsg.payload[\"count\"] = 0;\nreturn [msg,null];\n}\n","outputs":"2","noerr":0,"x":350,"y":223,"wires":[["577ae7e1.0c1948"],["b2204e3f.44cef"]]},{"id":"577ae7e1.0c1948","type":"function","z":"901492e5.e9666","name":"func1","func":"msg.payload.count++;\nreturn msg;","outputs":1,"noerr":0,"x":352,"y":316,"wires":[["1a6b10c8.0788cf"]]},{"id":"4e8f3348.10ab0c","type":"debug","z":"901492e5.e9666","name":"","active":true,"console":"false","complete":"payload","x":783.5,"y":332,"wires":[]},{"id":"b2204e3f.44cef","type":"function","z":"901492e5.e9666","name":"func3","func":"msg.payload.count++;\nreturn msg;","outputs":1,"noerr":0,"x":619,"y":332,"wires":[["4e8f3348.10ab0c"]]},{"id":"5bf50c74.5376e4","type":"inject","z":"901492e5.e9666","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":160,"y":422,"wires":[["c9b5e6b.ae91818"]]},{"id":"c9b5e6b.ae91818","type":"function","z":"901492e5.e9666","name":"func10","func":"if(msg.payload.second_call){return [null,msg];}\nelse {msg.payload[\"second_call\"] = true;\nmsg.payload[\"count\"] = 0;\nreturn [msg,null];\n}\n","outputs":"2","noerr":0,"x":345,"y":422,"wires":[["f11eb781.083348"],["b2204e3f.44cef"]]},{"id":"f11eb781.083348","type":"function","z":"901492e5.e9666","name":"func11","func":"msg.payload.count+=10;\nreturn msg;","outputs":1,"noerr":0,"x":348,"y":508,"wires":[["c9b5e6b.ae91818"]]}]
答案 0 :(得分:0)
这里有一些选择。
如果您打算使用"功能"多次,然后你可以把它包装在一个子流程中。这意味着要编辑一个代码副本,您可以将其链接到没有共同结束的流中。
如果您不打算更改"功能"完成后,您可以将其添加到functionGlobalContext
中的settings.js
。这将允许您将其包含在给定的函数节点中。有关如何使用上下文,请参阅doc。这意味着您无需重新启动Node-RED