[英]Extract from a NODE-RED string
I have my NODE-RED schemma: 我有NODE-RED方案:
following string result from my "Function" node my node: 我的“功能”节点到我的节点的以下字符串结果:
msg.payload : string[63]
"{"random":{"date":"22:55","random":21},"time":{"time":"22:52"}}"
This is the code of my "Function Node": 这是我的“功能节点”的代码:
msg.payload.random=context.global.randomandtime;
msg.payload.time=context.global.time;
return msg;
I need to put in "part of the string" (not all) like this =>{"date":" 22:55 ","random": 21 } and show it in my browser like a webpage but not using html tags. 我需要像这样=> {“ date”:“ 22:55 ”,“ random”: 21 }放入“字符串的一部分”(不是全部),并像网页一样在浏览器中显示它,但不使用html标签。
Like this: 像这样:
22:55 22:55
21 21
Any help will be wellcome. 任何帮助都会很好。
I have added template(Mustache) and I am traying to bring data to it,(Note:http response is already in schemme but not shown here) 我已经添加了模板(小胡子),并在托盘中添加数据(注意:http响应已经存在,但此处未显示)
I am traying to bring data here (template). 我正在将数据带到这里(模板)。 But I get error.
但是我得到了错误。
The Mustache template body is: 小胡子模板主体为:
This is the payload: {{#payload.randomandandtime.random}} ! 这是有效负载:{{#payload.randomandandtime.random}}!
But I have back this error back: 但是我又回来了这个错误:
2017-5-18 16:18:00node: Mustachemsg : string[56] 2017-5-18 16:18:00节点:Mustachemsg:字符串[56]
"Unclosed section "payload.randomandandtime.random" at 59" “ 59的未关闭部分“ payload.randomandtime.random”
In browser I get 在浏览器中我得到
502 Bad Gateway: Registered endpoint failed to handle the request. 502错误的网关:注册的端点无法处理该请求。
Even If I change it only payload.randomandandtime I get empty: 即使我只更改了payload.randomandandtime,我还是空着:
payload.randomandandtime payload.randomandandtime
In browser & console: 在浏览器和控制台中:
Messsage received back: (empty) This is the payload: ! 收到的邮件:(空)这是有效载荷:!
Finally I solved in this way. 最终我以这种方式解决了。 I make all in one Global varaible instead 2 global variables.
我将所有变量设为一个全局变量,而不是两个全局变量。 I passed it to mustache template and in Mustache I worked with context in order to get it.
我将其传递给Mustache模板,在Mustache中我使用上下文来获取它。
Then in recoverydata: 然后在recoverydata中:
msg.payload = context.global.get("randomtime");
In My Mustache: 在我的胡须中:
`{{#payload.random}}
Last random number request returned {{&payload.random}}, which was received
at {{&payload.randomtime.times}}{{/payload.random}}
{{/payload}}`
The resul of it is a Webservice not using HTML and this is: 它的结果是不使用HTML的Web服务,这是:
url https://....../page 网址https://....../page
"Time last server time request received at 13:14 Last random number request returned 94, which was received at 13:14" “在13:14收到的上次服务器时间请求的时间返回了在13:14收到的最后一个随机数请求94”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.