[英]Toggle checkbox in Angular JS repeater table by clicking enclosing row
I have a table constructed with ng-repeat, where each row has a checkbox set by a value in the JSON data that's being repeated: 我有一个用ng-repeat构造的表,其中每一行都有一个复选框,该复选框由重复的JSON数据中的值设置:
<tr ng-repeat="t in tabledata" ng-click="t.isChecked=t.!isChecked">
<td><input type="checkbox" ng-model="t.isChecked"></td>
<td>{{t.firstName}} {{t.lastName}}</td>
</tr>
I would like a click on the row to toggle the checkbox value in that row. 我想点击该行来切换该行中的复选框值。 I tried the above, but it does not work. 我尝试了以上,但它不起作用。 Thoughts? 思考?
Try this: 试试这个:
ng-click="t.isChecked = !t.isChecked"
Exclamation sign should go in front of t.isChecked
. 感叹号应该在t.isChecked
前面。
Also make sure you stop propagation of the click event on the checkbox itself, otherwise clicking on the checkbox will not allow you to check/uncheck anything. 还要确保停止在复选框本身上传播click事件,否则单击复选框将不允许您选中/取消选中任何内容。
<input type="checkbox" ng-model="t.isChecked" ng-click="$event.stopPropagation()">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.