简体   繁体   English

Node-red:从 msg.payload 获取值并将其保存在变量中

[英]Node-red: get value from msg.payload and save it inside variable

how can I take the value from msg.payload and put it inside variable then I can use this variable in different functions (node-red)如何从 msg.payload 中获取值并将其放入变量中,然后我可以在不同的函数中使用这个变量(节点红色)

Each msg is just a javascript object, and using msg.payload to contain the data a node operates on is really more of a convention than a hard rule (ie: most of the nodes in node-red look for data in the msg.payload field).每个msg只是一个 javascript object,使用msg.payload包含节点操作的数据实际上更像是一种约定而不是硬性规则(即:大多数节点红色的节点在msg.payload中查找数据场地)。 However, you can also attach data to any other property in the msg object, with the exception of the id field.但是,您也可以将数据附加到msg object 中的任何其他属性, id字段除外。

When you pass that message from one node to another, you can then access your stored data using the msg object.当您将该消息从一个节点传递到另一个节点时,您可以使用msg object 访问您存储的数据。

If you store a query in msg.query , for example, you can access it in a subsequent node in the flow by just accessing the msg.query object.例如,如果您将查询存储在msg.query中,您可以通过访问msg.query object 在流中的后续节点中访问它。

Add this to a function node:将此添加到 function 节点:

global.set("Variable_name_here",msg.payload);

This will store the msg.paylog (received on the input of the node) to a global variable that can be used at any time, from any flow.这会将msg.paylog (在节点的输入上接收)存储到一个全局变量中,该变量可以在任何时间、任何流中使用。

In order to use the variable add this to a function node: var M =global.get("Variable_name_here");为了使用该变量,请将其添加到 function 节点: var M =global.get("Variable_name_here");

This will set the global variable value to the local variable M, to be used in your node.这会将全局变量值设置为局部变量 M,以便在您的节点中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 node-red 中的 msg.payload 运行 javascript 函数 - run javascript function using msg.payload in node-red 如何在节点红色中增加msg.payload [i] - How to increment msg.payload[i] in node-red node-red 将 json 字符串解析为 msg.payload - node-red parsing a json string to msg.payload 在节点红色中仅显示msg.payload中的值字段 - display only value fields from the msg.payload in node red node-red 无法在模板节点和 JS 标签上获取 msg.payload - node-red cannot get msg.payload on template node unde JS tag 您如何使用JavaScript在Node-Red中的msg.payload中解码HTML实体? - How would you decode HTML entities inside the msg.payload in Node-Red with javascript? 如何从节点红色仪表板模板发送msg.payload Int16Array - How to send msg.payload Int16Array from node-red dashboard template 如何将msg.payload存储到ui_template节点红色内的脚本变量中? - How to store a msg.payload into a script variable inside a ui_template node red? 在循环中的仪表板ui_template(node-red)中创建复选框,并将check-status分配给输出msg.payload - create checkbox in dashboard ui_template (node-red) in loop and assign check-status to output msg.payload 如何将 msg.payload 从注入节点移动到节点红色仪表板中的模板节点? - How to move msg.payload from inject node to template node in node red dashboard?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM