【发布时间】:2018-12-19 16:45:00
【问题描述】:
我有一些使用 ngFor 指令在表中显示的数据。我在最后一列中有复选框,我希望它只选择将被选中的行,而不是其他行。这是我的代码
HTML 代码
<div *ngIf="!admin">
<div class="row clearfix">
<div class="col-sm-12">
<input type="checkbox" name="permission12" value="" (change)="isSelected = !isSelected" class="filled-in" id="permission12" (click)="chosen(listSupportAdminSchools.items)" />
<label for="permission12">: Select All</label>
<table class="table-bordered table-striped" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Registration Number</th>
<th>Enrollment Type</th>
<th>Entity Type</th>
<th>Location</th>
<th>IsActive</th>
<th>Select</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let x of listSupportAdminSchools.items;">
<td>{{x.name}}</td>
<td>{{x.registrationNumber}}</td>
<td>{{x.educationType}}</td>
<td>{{x.administrativeType}}</td>
<td>{{x.county}}
<span>,</span>{{x.city}}
<span>,</span>{{x.district}}</td>
<td></td>
<td style="text-align: center">
<!-- <button (click)="onClick()" class="btn btn-primary waves-effect">Select</button> -->
<input type="checkbox" name="permission13" value="" [(ngModel)] = "isSelected" class="validate form-control" id="permission13" (click)="chosen()" />
<label for="permission13">: Select</label>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
在我的 .ts 文件中,我将 isSelected 布尔变量设置为 false。
每当我点击行中的一个复选框时,它也会选择另一个。但是全选复选框工作得很好
【问题讨论】:
-
希望这个答案能帮助stackoverflow.com/a/50173653/7392985
-
啊,我希望它有帮助,但不,它根本没有帮助,因为您看到我在表格中显示数据的代码结构不同,我需要一个解决方案。
-
你绑定名字动态
-
是的,我知道这是不同的,你必须即兴发挥一点。抱歉,我现在无法为您的代码结构发布解决方案。如果您仍然有这个问题,可能会在今晚晚些时候,我会发布答案。
-
我真的很感激这个答案,只要你能发布它
标签: html angular typescript