我目前正在尝试为个人项目创建自定义 Node 。我需要保存服务器的配置,所以我想使用 config node
问题是,我没有在自定义 Node 的“Node 属性”中看到配置选择器,而是只看到一个文本框。
这是我的 package.json 文件的摘录:
"node-red": {
"nodes": {
"authentication": "authentication-node/authentication.js",
"accessconfig": "configuration-node/configuration.js"
}
}
我的configuration.js文件:
module.exports = function(RED) {
/*
Configuration node functions
*/
function ConfigurationNode(n) {
RED.nodes.createNode(this,n);
this.username = n.username;
this.password = n.password;
}
RED.nodes.registerType("accessconfig",ConfigurationNode,{
credentials: {
username: {type:"text"},
password: {type:"password"}
}
});
}
我的configuration.html文件:
<!--Config node-->
<script type="text/javascript">
RED.nodes.registerType('accessconfig',{
category: 'config',
defaults: {
name: {value:""}
},
credentials: {
service-username: {type:"text"},
service-password: {type:"password"}
}
});
</script>
<script type="text/x-red" data-template-name="accessconfig">
<div class="form-row">
<label for="node-config-input-name"><i class="icon-tag"></i>Name</label>
<input type="text" id="node-config-input-name">
</div>
<div class="form-row">
<label for="node-config-input-username"><i class="icon-tag"></i>Username</label>
<input type="text" id="node-config-input-username">
</div>
<div class="form-row">
<label for="node-config-input-password"><i class="icon-tag"></i>Password</label>
<input type="password" id="node-config-input-password">
</div>
</script>
<script type="text/x-red" data-help-name="accessconfig">
<p>Help text.</p>
</script>
我的authentication.js文件:
module.exports = function(RED) {
/*
Authentication node functions
*/
function AuthenticationNode(config) {
RED.nodes.createNode(this,config);
var node = this;
// Retrieve the configuration node
node.configuration = RED.nodes.getNode(config.configuration);
if (node.configuration) {
} else {
}
}
RED.nodes.registerType("authentication",AuthenticationNode);
}
我的authentication.html文件:
<!-- Authentication node-->
<script type="text/javascript">
RED.nodes.registerType('authentication',{
category: 'test',
color: '#a6bbcf',
defaults: {
name: {value:""},
configuration: {value:"",type:"accessconfig",required:true}
},
inputs:0,
outputs:0,
icon: "file.png",
label: function() {
return this.name||"Authentication";
}
});
</script>
<script type="text/x-red" data-template-name="authentication">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-configuration">Configuration</label>
<input type="text" id="node-input-configuration">
</div>
</script>
<script type="text/x-red" data-help-name="authentication">
<p>Help text.</p>
</script>
最佳答案
解决方案:
如果有人遇到与我相同的问题,我会将其发布在这里。问题似乎出在配置凭据的名称(“服务用户名”和“服务密码”)中。当我将它们更改为“用户名”和“密码”时,一切都按预期工作。
关于javascript - 创建 Node-Red 自定义 Node : config not working, 显示文本框而不是配置下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53011346/