简体   繁体   English

单击封闭行,在Angular JS转发器表中切换复选框

[英]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()">

Demo: http://plnkr.co/edit/KJziWDmlN2gTbthOF4yJ?p=preview 演示: http//plnkr.co/edit/KJziWDmlN2gTbthOF4yJ?p = preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM