node-red, 自定义节点, require/include js in node html

Node-red, custom nodes, require/include js in node html

我创建了一个函数,我在 "oneditprepare" 中调用它,它工作正常但因为它相当大并且我计划在其他节点中使用它,我想将它放在一个单独的文件中,到目前为止,我一直无法做到这一点,我已经尝试在包含节点定义的文件上方添加带有脚本标签的文件,但似乎 node-red 不会将文件(具有我的功能的文件)发送到前端,我也试过在 "functionGlobalContext" 中要求它,但这只会使它在服务器端(js 文件)可用,而且我在前面需要它,因为我正在操作 DOM这个函数,我尝试的最后一件事是将函数放在 html 文件的脚本标记中,但再一次,node-red 似乎没有将它发送到前面。

Here what I had before (this worked):

我的-node.html

<script type="text/javascript">
    RED.nodes.registerType('create-issue', {
        .
        .
        .
        oneditprepare: function() {
            function myVeryLargeFunction() {
                // Do stuff here
            }

            myVeryLargeFunction();
        }
        .
        .
        .
    });
</script>

Here an example of what I'm trying to accomplish:

我的-node.html

<script type="text/javascript">
    RED.nodes.registerType('create-issue', {
        .
        .
        .
        oneditprepare: function() {
            // some kind of require here
            myVeryLargeFunction();
        }
        .
        .
        .
    });
</script>

我的非常大-function.js

function myVeryLargeFunction() {
    // Do stuff here
}

看看 geofence node 这会动态加载传单脚本文件以支持将地图添加到配置对话框。

您必须使用 jquery 的加载程序才能使其正常工作,示例代码大约从第 190 行开始。

$.getScript('geofence/js/leaflet/leaflet-src.js')
.done(function(data, textStatus, jqxhr) {
  ...
})