在循环中的仪表板 ui_template(节点红色)中创建复选框并将检查状态分配给输出 msg.payload
create checkbox in dashboard ui_template (node-red) in loop and assign check-status to output msg.payload
我正在根据初始输入 msg.payload 在循环中创建复选框(请参阅下面的有效代码)。
传入有效负载的示例:
msg.payload=[{"NAME":"a"},{"NAME":"b"}]
<form>
<fieldset style="width:85%">
<legend>choose chartdata</legend>
<div ng-repeat="x in msg.payload">
<input type="checkbox" name={{msg.payload[$index].NAME}}>
<label for={{msg.payload[$index].NAME}}>{{msg.payload[$index].NAME}}</label>
</div>
</fieldset>
</form>
我正在尝试为每个包含复选框名称(此处:"a" 或 "b") 和状态 (checked/unchecked).
有人知道如何做到这一点吗?
p.s.: 这里是流程:
[{"id":"3bbd849e.391734","type":"inject","z":"256e6f3d.da9f7","name":"","topic":"","payload":"[{\"NAME\":\"a\"},{\"NAME\":\"b\"}]","payloadType":"json","repeat":"","crontab":"","once":false,"x":341.08331298828125,"y":216.08334350585938,"wires":[["f6bae45e.b99088"]]},{"id":"f6bae45e.b99088","type":"ui_template","z":"256e6f3d.da9f7","group":"34890ec3.1f4b6a","name":"checkbox","order":11,"width":"3","height":"8","format":"<form>\n <fieldset style=\"width:85%\">\n <legend>choose chartdata</legend>\n <div ng-repeat=\"x in msg.payload\">\n <input type=\"checkbox\" name={{msg.payload[$index].NAME}}>\n <label for={{msg.payload[$index].NAME}}>{{msg.payload[$index].NAME}}</label>\n </div>\n </fieldset>\n</form>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":513.4889526367188,"y":217.39315795898438,"wires":[[]]},{"id":"34890ec3.1f4b6a","type":"ui_group","name":"Group 1","tab":"a52427c4.c3901","order":1,"disp":true,"width":6},{"id":"a52427c4.c3901","type":"ui_tab","z":"","name":"test","icon":"dashboard","order":12}]
此代码似乎有效:
<form>
<fieldset style="width:85%">
<legend>choose chartdata</legend>
<div ng-repeat="x in msg.payload">
<label>{{x.NAME}}
<input type="checkbox" style="float:left; position: relative; top: 5px;"
ng-model="check"
ng-change="send({var:x.NAME, state:check})">
</label>
</div>
</fieldset>
</form>
取消选中 "Pass through messages from input." 和 "Add output messages to stored state." in ui_template
我正在根据初始输入 msg.payload 在循环中创建复选框(请参阅下面的有效代码)。 传入有效负载的示例: msg.payload=[{"NAME":"a"},{"NAME":"b"}]
<form>
<fieldset style="width:85%">
<legend>choose chartdata</legend>
<div ng-repeat="x in msg.payload">
<input type="checkbox" name={{msg.payload[$index].NAME}}>
<label for={{msg.payload[$index].NAME}}>{{msg.payload[$index].NAME}}</label>
</div>
</fieldset>
</form>
我正在尝试为每个包含复选框名称(此处:"a" 或 "b") 和状态 (checked/unchecked).
有人知道如何做到这一点吗?
p.s.: 这里是流程:
[{"id":"3bbd849e.391734","type":"inject","z":"256e6f3d.da9f7","name":"","topic":"","payload":"[{\"NAME\":\"a\"},{\"NAME\":\"b\"}]","payloadType":"json","repeat":"","crontab":"","once":false,"x":341.08331298828125,"y":216.08334350585938,"wires":[["f6bae45e.b99088"]]},{"id":"f6bae45e.b99088","type":"ui_template","z":"256e6f3d.da9f7","group":"34890ec3.1f4b6a","name":"checkbox","order":11,"width":"3","height":"8","format":"<form>\n <fieldset style=\"width:85%\">\n <legend>choose chartdata</legend>\n <div ng-repeat=\"x in msg.payload\">\n <input type=\"checkbox\" name={{msg.payload[$index].NAME}}>\n <label for={{msg.payload[$index].NAME}}>{{msg.payload[$index].NAME}}</label>\n </div>\n </fieldset>\n</form>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":513.4889526367188,"y":217.39315795898438,"wires":[[]]},{"id":"34890ec3.1f4b6a","type":"ui_group","name":"Group 1","tab":"a52427c4.c3901","order":1,"disp":true,"width":6},{"id":"a52427c4.c3901","type":"ui_tab","z":"","name":"test","icon":"dashboard","order":12}]
此代码似乎有效:
<form>
<fieldset style="width:85%">
<legend>choose chartdata</legend>
<div ng-repeat="x in msg.payload">
<label>{{x.NAME}}
<input type="checkbox" style="float:left; position: relative; top: 5px;"
ng-model="check"
ng-change="send({var:x.NAME, state:check})">
</label>
</div>
</fieldset>
</form>
取消选中 "Pass through messages from input." 和 "Add output messages to stored state." in ui_template