将HTML-File中的config-node参数传递给另一个节点

问题描述 投票:0回答:1

我创建了以下输入节点:

<script type="text/javascript">
RED.nodes.registerType('Sensor',{
    category: 'input',
    defaults: {
        name: {type:"InputDevice", required:true},
        count: {value:"", required:true, validate:RED.validators.number()},
        topic: {value:"",validate: RED.validators.regex(/^(#$|(\+|[^+#]*)(\/(\+|[^+#]*))*(\/(\+|#|[^+#]*))?$)/)},
        qos: {value: "1"},
        broker: {type:"mqtt-broker", required:true},
    },
    color:"#3FADB5",
    inputs:0,
    outputs:1,
    icon: "feed.png",
    label: function() {
        //var testu = RED.nodes.getNode(config.name).inputDeviceName;
        //return this.name.inputDeviceName;
        return this.name||this.topic||"ClientName";
    },
    labelStyle: function() {
        return this.name?"node_label_italic":"";
    },
});

并在配置节点后面:

<script type="text/javascript">
RED.nodes.registerType('InputDevice',{
    category: 'config',
    defaults: {
        inputDeviceName: {value:"",required:true},
    },
    label: function() {
        return this.inputDeviceName;
    }
});

我无法弄清楚,如何传递参数

inputDeviceName

到HTML文件中的传感器节点。在JS文件中,我能够获得inputDeviceName的值:

this.name = RED.nodes.getNode(config.name).inputDeviceName;

我如何命名传感器节点,如上例所示,在我的流程中显示为“LDR”?

html node.js node-red
1个回答
0
投票

您可以使用RED.nodes.node(node_id)访问HTML文件中您知道id的任何节点的属性。这将返回此节点的默认属性。

例如,如果您需要配置节点中的某些属性,则可以从与配置节点关联的select HTML元素的值中获取其id。

© www.soinside.com 2019 - 2024. All rights reserved.