这个部分解决方案怎么样?
我想存储(使用 Config 节点)一个全局 bigobj,带有数据 + 方法(作为导入外部库的替代方法),在我的流程中的许多功能节点中使用:
奇怪但有效:
全局变量“bigobj”:
{
some[]more[]{dx:"here"} , // array of objects with array of objects. The 'Config' node requires JSON.
.....
"get_dx": "function( d,p) { return this.some[d].more[p].dx; }" // test function
}
即函数的 JSON 版本....(全部在一行中:()
使用:
函数节点内部:
var bigO = global.get("bigobj");
function callJSONMethod(obj, fname, a, b, c, d){
// see: https://stackoverflow.com/questions/49125059/how-to-pass-parameters-to-an-eval-based-function-injavascript
var wrap = s => "{ return " + obj[fname] + " };" //return the block having function expression
var func = new Function(wrap(obj[fname]));
return func.call( null ).call( obj, a, b, c, d); //invoke the function using arguments
}
msg.payload =callJSONMethod(bigO, "get_dx", 2, 2);
return msg:
返回“这里”,难以置信!
即我必须使用 bigobj 将函数 callJSONMethod() 添加到任何功能块.....
也许可以接受。
最好的问候