2017-02-17 56 views
1

我在節點紅色瀏覽器ide上有一個mqtt節點,它正在監聽有關主題的傳入消息。節點紅色儀表板 - 插入列表在Mqtt請求

我要填寫的節點,紅色的儀表板與信息的列表,所以我添加了該格式的模板節點:

<ul id="messagesList"></ul> 

,我不僅要添加這些信息,這樣可以通過完成一個角度綁定我也想刪除舊的條目,以便最多3條消息在表中。所以我需要在每個可以訪問儀表板頁面的傳入消息上運行JavaScript。

我該如何做到這一點?每當消息進入時,如何運行javascript訪問html頁面?

回答

1

添加一個函數節點,將消息存儲在流上下文中。

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"}]