Hi,
I tried config node following Configuration nodes : Node-RED (nodered.org), I wrote remote-server.html
// remote-server.html
<script type="text/javascript">
RED.nodes.registerType('remote-server',{
category: 'config',
defaults: {
host: {value:"localhost",required:true},
port: {value:1234,required:true,validate:RED.validators.number()},
},
label: function() {
return this.host+":"+this.port;
}
});
</script>
<script type="text/html" data-template-name="remote-server">
<div class="form-row">
<label for="node-config-input-host"><i class="fa fa-bookmark"></i> Host</label>
<input type="text" id="node-config-input-host">
</div>
<div class="form-row">
<label for="node-config-input-port"><i class="fa fa-bookmark"></i> Port</label>
<input type="text" id="node-config-input-port">
</div>
</script>
and remote-server.js
module.exports = function(RED) {
function RemoteServerNode(n) {
RED.nodes.createNode(this,n);
this.host = n.host;
this.port = n.port;
}
RED.nodes.registerType("remote-server",RemoteServerNode);
}
and I want to quote the remote server node in test node, here are the .js and .html file:
test.html
<script type="text/javascript">
RED.nodes.registerType('test',{
category: 'function',
color: '#a6bbcf',
defaults: {
server: {value:"", type:"remote-server"}
},
inputs: 1,
outputs: 1,
icon: "file.svg",
label: function() {
return this.name||"test";
}
</script>
<script type="text/html" data-template-name="test">
<div class="form-row">
<label for="node-input-server"><i class="fa fa-tag"></i> Server</label>
<input type="text" id="node-input-server">
</div>
</script>
<script type="text/html" data-help-name="test">
<p>A simple node for configuring
</script>
test.js
module.exports = function(RED) {
function TestNode(config) {
RED.nodes.createNode(this,config);
var node = this;
this.server = RED.nodes.getNode(config.server);
node.log(this.server);
node.log("host =");
node.log(this.server.host);
node.log("port =");
node.log(this.server.port);
node.on('input', function(msg) {
node.send(msg);
});
}
RED.nodes.registerType("test",TestNode);
When I started node-red, it showed that this.server is null. How can i use the config node ? Thanks.