[英]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.