添加一個函數節點,將消息存儲在流上下文中。
var message = msg.payload;
var messages = flow.get("messagesList") || [];
if(messages.length < 3) {
//Push to message list
messages.push(message);
} else {
//Remove first message and add new one
messages.splice(0,1);
messages.push(message);
}
flow.set("messagesList", messages);
msg.payload = messages;
return msg;
在dahsboard模板節點,採用NG-重複顯示您的列表,例如:
<ul id="messagesList">
<li ng-repeat="x in msg.payload">{{x}}</li>
</ul>
工作例如:
[{"id":"5c713e84.dacb98","type":"function","z":"47849408.20a044","name":"","func":"var message = msg.payload;\nvar messages = flow.get(\"messagesList\") || [];\n\nif(messages.length < 3) {\n\n //Push to message list\n messages.push(message);\n} else {\n\n //Remove first message and add new one\n messages.splice(0,1);\n messages.push(message);\n}\n\nflow.set(\"messagesList\", messages);\n\nmsg.payload = messages;\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":500,"wires":[["e6bdd32f.ec218"]]},{"id":"e6bdd32f.ec218","type":"ui_template","z":"47849408.20a044","group":"77d3195c.d9af28","name":"","order":0,"width":0,"height":0,"format":"<ul id=\"messagesList\">\n <li ng-repeat=\"x in msg.payload\">{{x}}</li>\n</ul>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":460,"y":500,"wires":[[]]},{"id":"87e7fba4.ccfa6","type":"inject","z":"47849408.20a044","name":"","topic":"","payload":"","payloadType":"date","repeat":"2","crontab":"","once":false,"x":150,"y":500,"wires":[["5c713e84.dacb98"]]},{"id":"77d3195c.d9af28","type":"ui_group","z":"","name":"Sensors","tab":"cd626a92.d20a78","disp":true,"width":"9"},{"id":"cd626a92.d20a78","type":"ui_tab","z":"","name":"Dashboard","icon":"dashboard"}]