Dynamically Changing the Number of Outputs of a Node

906 views
Skip to first unread message

mkmm...@gmail.com

unread,
Mar 6, 2015, 11:45:10 AM3/6/15
to node...@googlegroups.com
Hello everyone,


I have created a node that gets updates from a server and I would like it to allow for unknown number of multiple outputs chosen by the user.  I know in the node html file where you declare your node, you can specify in the JSON object the exact number of nodes, but this is then set, and I would like the user to be able to decide (like how the function node you can specify 2,3 or 4 outputs dynamically).

I am a bit of a beginner in programming, and I was wondering if there is a relatively easy way to accomplish this? I noticed for all the predefined nodes that come with node-red they are all a set output except for function which is the only one that can change dynamically.

If anyone has done this before, it would be appreciated if they could point to me to where they did so I could look at the code. I tried looking at the function code and it seems like it is uniquely built in to the function (ie: no simple setting like to pre-set the number of outputs)

Thank you.

Dave C-J

unread,
Mar 6, 2015, 11:55:40 AM3/6/15
to node...@googlegroups.com
The switch node also has a variable number of output that changes dynamically based on the number of terms used - so may be a better model to look at.

Nicholas O'Leary

unread,
Mar 6, 2015, 12:21:21 PM3/6/15
to Node-RED Mailing LIst
In the list of the node's default properties that can be configured, the Function node (and as Dave points out, the Switch node), has a property called 'outputs' - https://github.com/node-red/node-red/blob/master/nodes/core/core/80-function.html#L63

When the node is edited, this property can be edited just as any other. When the dialog is closed, the editor checks to see if node.outputs has changed and updates the node accordingly.

Nick

 

On 6 March 2015 at 16:55, Dave C-J <dce...@gmail.com> wrote:
The switch node also has a variable number of output that changes dynamically based on the number of terms used - so may be a better model to look at.

--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mkmm...@gmail.com

unread,
Mar 6, 2015, 1:27:05 PM3/6/15
to node...@googlegroups.com
Thank you Nicholas and Dave for your fast response. The Switch node was perfect for understanding and now I have it working in my own node. Thanks.
Reply all
Reply to author
Forward
0 new messages