我在 node-red 中的自定义节点在进入流程后无法使用
My custom node in node-red is unusable after dropped into flow
我正在尝试在 Node-red 中创建一个自定义节点,但是当我将该节点放入流程中时,该节点“卡住”并且无法使用。控制台 (F12) 的错误是:
Uncaught TypeError: Cannot read property 'hasOwnProperty' of undefined
at HTMLDivElement.drop (red.min.js:16)
at t.<computed>.<computed>._trigger (vendor.js:10)
at t.<computed>.<computed>._drop (vendor.js:15)
at t.<computed>.<computed>._drop (vendor.js:10)
at t.<computed>.<computed>.<anonymous> (vendor.js:15)
at Function.each (vendor.js:2)
at Object.drop (vendor.js:15)
at t.<computed>.<computed>._mouseStop (vendor.js:13)
at t.<computed>.<computed>._mouseStop (vendor.js:10)
at t.<computed>.<computed>._mouseUp (vendor.js:13)
我已经尽可能地简化了我的节点,但它仍然无法正常工作。这是我的代码:
findProtocol.js:
module.exports = function(RED) {
function FindProtocolNode(config) {
RED.nodes.createNode(this,config);
var msg = { payload:"hi" }
this.send(msg);
}
RED.nodes.registerType("findProtocol",FindProtocolNode);
}
findProtocol.html:
<script type="text/javascript">
RED.nodes.registerType('findProtocol',{
category: "Rpi RF Tools",
outputs: 1,
label: "Find Protocol"
});
</script>
package.json:
{
"name": "node-red-contrib-rpi-rf-tools",
"version": "1.0.0",
"description": "",
"node-red": {
"nodes": {
"findProtocol": "src/findProtocol/findProtocol.js"
}
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"pigpio": "^3.2.4",
"simple-statistics": "^7.3.2"
}
}
有什么想法吗?
我怀疑编辑器希望您的节点在其 HTML 定义中有一个 defaults
属性,即使它是空的 属性.
<script type="text/javascript">
RED.nodes.registerType('findProtocol',{
category: "Rpi RF Tools",
outputs: 1,
label: "Find Protocol",
defaults: {}
});
</script>
https://nodered.org/docs/creating-nodes/properties
至少,您的节点应该有一个 name
属性,这样用户就可以在编辑器中给它自定义 name/label。
我正在尝试在 Node-red 中创建一个自定义节点,但是当我将该节点放入流程中时,该节点“卡住”并且无法使用。控制台 (F12) 的错误是:
Uncaught TypeError: Cannot read property 'hasOwnProperty' of undefined
at HTMLDivElement.drop (red.min.js:16)
at t.<computed>.<computed>._trigger (vendor.js:10)
at t.<computed>.<computed>._drop (vendor.js:15)
at t.<computed>.<computed>._drop (vendor.js:10)
at t.<computed>.<computed>.<anonymous> (vendor.js:15)
at Function.each (vendor.js:2)
at Object.drop (vendor.js:15)
at t.<computed>.<computed>._mouseStop (vendor.js:13)
at t.<computed>.<computed>._mouseStop (vendor.js:10)
at t.<computed>.<computed>._mouseUp (vendor.js:13)
我已经尽可能地简化了我的节点,但它仍然无法正常工作。这是我的代码:
findProtocol.js:
module.exports = function(RED) {
function FindProtocolNode(config) {
RED.nodes.createNode(this,config);
var msg = { payload:"hi" }
this.send(msg);
}
RED.nodes.registerType("findProtocol",FindProtocolNode);
}
findProtocol.html:
<script type="text/javascript">
RED.nodes.registerType('findProtocol',{
category: "Rpi RF Tools",
outputs: 1,
label: "Find Protocol"
});
</script>
package.json:
{
"name": "node-red-contrib-rpi-rf-tools",
"version": "1.0.0",
"description": "",
"node-red": {
"nodes": {
"findProtocol": "src/findProtocol/findProtocol.js"
}
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"pigpio": "^3.2.4",
"simple-statistics": "^7.3.2"
}
}
有什么想法吗?
我怀疑编辑器希望您的节点在其 HTML 定义中有一个 defaults
属性,即使它是空的 属性.
<script type="text/javascript">
RED.nodes.registerType('findProtocol',{
category: "Rpi RF Tools",
outputs: 1,
label: "Find Protocol",
defaults: {}
});
</script>
https://nodered.org/docs/creating-nodes/properties
至少,您的节点应该有一个 name
属性,这样用户就可以在编辑器中给它自定义 name/label。