Node-RED 在输入字段中使用多个环境变量
Node-RED use of more than one environment variable in an input field
我有一个简单的问题,我想不通。
我有一个子流,我在其中定义了 3 个环境变量。
我还有一个 http in
节点。
我想要做的是像这样设置节点的 url 字段:
${some_var}/${other_var}
当我在 URL 字段中使用单个环境变量时,它工作正常,但是当我像示例中那样使用它时,它不起作用。
我已经尝试了很多东西,但无法让它发挥作用。
我现在也在网上搜索了大约 2 个小时,但找不到任何东西。
会不会是 Node-RED 不支持类似的东西?
有没有办法让这个工作?
不,你不能这样做。
您不能在节点配置字段中串联环境变量。运行时只会获取环境变量的值并用它替换整个字段,而不是 assemble 来自多个环境变量和静态字符串的字符串。
参见 docs 中的第二段:
This only works if it replaces the entire property - it cannot be used
to substitute just part of the value. For example, it is not possible
to use CLIENT-${HOST}.
有关在 Node-RED 中使用环境变量的文档位于:https://nodered.org/docs/user-guide/environment-variables(google 上的最高搜索结果)。
第二句说:
This only works if it replaces the entire property - it cannot be used to substitute just part of the value. For example, it is not possible to use CLIENT-${HOST}
.
当您在子流中时,您可以使用环境变量类型定义子流的 属性 - 这种类型确实支持将环境变量连接在一起。然后,您可以使用该子流 属性 作为节点中的环境变量。
以下屏幕截图显示了如何定义名为 MY_URL
.
的环境变量
我有一个简单的问题,我想不通。
我有一个子流,我在其中定义了 3 个环境变量。
我还有一个 http in
节点。
我想要做的是像这样设置节点的 url 字段:
${some_var}/${other_var}
当我在 URL 字段中使用单个环境变量时,它工作正常,但是当我像示例中那样使用它时,它不起作用。
我已经尝试了很多东西,但无法让它发挥作用。
我现在也在网上搜索了大约 2 个小时,但找不到任何东西。
会不会是 Node-RED 不支持类似的东西? 有没有办法让这个工作?
不,你不能这样做。
您不能在节点配置字段中串联环境变量。运行时只会获取环境变量的值并用它替换整个字段,而不是 assemble 来自多个环境变量和静态字符串的字符串。
参见 docs 中的第二段:
This only works if it replaces the entire property - it cannot be used to substitute just part of the value. For example, it is not possible to use CLIENT-${HOST}.
有关在 Node-RED 中使用环境变量的文档位于:https://nodered.org/docs/user-guide/environment-variables(google 上的最高搜索结果)。
第二句说:
This only works if it replaces the entire property - it cannot be used to substitute just part of the value. For example, it is not possible to use
CLIENT-${HOST}
.
当您在子流中时,您可以使用环境变量类型定义子流的 属性 - 这种类型确实支持将环境变量连接在一起。然后,您可以使用该子流 属性 作为节点中的环境变量。
以下屏幕截图显示了如何定义名为 MY_URL
.