如何在父节点中获取配置节点的变量?

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

假设我在 Node-RED 中有一个节点,它使用名为 my-config-node 的配置节点作为其 属性。我想自定义我的标签函数,以便它显示 my-config-node 的变量 myVar

通常我会使用RED.nodes.getNode(如下所示)并传递节点id,但似乎不可用。

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 : '')
}

如何从正在使用它的节点获取配置节点的变量?

在编辑器中,您可以使用 RED.nodes.node() 函数来检索配置节点:

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