【发布时间】:2020-10-05 22:34:42
【问题描述】:
我有一个表,它的行是动态添加的。
我在 component.ts 文件中有一个数组,我在该数组上使用 *ngFor,所以我得到了与数组元素相同的行数。
那些动态添加的行是可点击的。单击该行将起到下拉菜单的作用,因此其下方会出现另一行,然后单击与之前相同的行,将关闭该下拉菜单,它将折叠。
在动态添加表格行之前,我为每个点击事件创建了 10 个不同的行,并且我有 10 个不同的“collapsed(1-2-3....)”变量。然后,每一行的下拉菜单都起作用了。 在动态添加行之后,以前的解决方案显然不起作用。单击一行后,所有行都以相同的方式执行(因为我使用的是一个变量)。
您能帮我修复它或告诉我如何修复它吗? :)
<table class="table col-12">
<tr class="d-flex col-12 clickable" (click)="collapsed=!collapsed" *ngFor="let log of logList">
<td class="col-1">
<i class="material-icons" *ngIf="!collapsed" aria-hidden="true">
keyboard_arrow_down
</i>
<i class="material-icons" *ngIf="collapsed" aria-hidden="true">
keyboard_arrow_right
</i>
<td>
<td class="col-1">
{{log.time}}
</td>
<td class="col-3">
{{log.text}}
</td>
<td class="col-7">
<!-- JSON file displayed-->
</td>
</tr>
<tr class="d-flex col-12" *ngIf="!collapsed">
<!-- dropdown row-->
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
单击行,也会更改第一列中的图标。
【问题讨论】:
-
您能否附上您想要的结果的图片。目前你得到了什么结果。因为我对你的第二个
tr有点困惑。它也会与第一个tr重复,或者它只是一个独立的信号tr。
标签: angular