levivanzele
levivanzele

Reputation: 736

How to get a config node's variables in the parent node?

Imagine I have a node in Node-RED that uses a config node called my-config-node as its property. I want to customize my label function so it display the my-config-node's variable myVar.

Normally I would use RED.nodes.getNode (as shown below) and pass the node id, but it seems it is not available.

label: function () {
  // RED.nodes.getNode is not available here
  const myConfig = RED.nodes.getNode(this.my-config-node)
  return this.name || 'myConfig:' + (myConfig ? myConfig.myVar : '')
}

How can I get to a variable of a config node from the node that is using it?

Upvotes: 1

Views: 270

Answers (1)

knolleary
knolleary

Reputation: 10117

Within the editor, you can use the RED.nodes.node() function to retrieve the config node:

label: function () {
  const myConfig = RED.nodes.node(this.my-config-node)
  return this.name || 'myConfig:' + (myConfig ? myConfig.myVar : '')
}

Upvotes: 2

Related Questions