我在折叠表格行数据时遇到问题。当我单击按钮时,它将切换所有子行,而不是恰好是子行。这是代码段:
<table class="table table-bordered table-hover">
<thead>
<tr>
<th class="">Үйлчилгээний ангилал</th>
<th class="">Код</th>
<th class="">Үйлчилсэн тоо</th>
<th class="">Зарцуулсан мин</th>
<th class="">Зорилт</th>
<th class="">Зорилт нөхөх</th>
</tr>
</thead>
<tbody *ngFor="let item of nodes; let i = index">
<tr>
<td>
<button
*ngIf="item.children.length > 0"
(click)="getchild($event,item.id)"
>
<i class="icon-arrow-right5"></i>
</button>
{{ item.name }}
</td>
<td>{{ item.code }}</td>
<td>{{ item.count }}</td>
<td>{{ item.elapsed }}</td>
<td>{{ item.goal }}</td>
<td>{{ item.children.length }}</td>
</tr>
<tr
*ngFor="let child of item.children"
[ngClass]="toggleChild ? 'expand' : 'collapse'"
>
<td>{{ child.name }}</td>
<td>{{ child.code }}</td>
<td>{{ child.elapsed }}</td>
<td>{{ child.goal }}</td>
<td>{{ child.goal }}</td>
<td>{{ child.goal }}</td>
</tr>
</tbody>
</table>
还有我的打字稿文件:
nodes = [
{
id: 1,name: "Санхүү",code: "-",count: "986",elapsed: "08:29",goal: "92%",children: [
{
id: 1,name: "Данс нээх харилцах",code: "5545",goal: "92%"
},{
id: 2,name: "Карт захиалах",code: "4587",goal: "82%"
}
]
},{
id: 2,name: "Санхүүгийн бус",goal: "80%",{
id: 3,name: "Дундаж",children: []
}
];
options = {};
private getchild(e: any,id: any) {
this.toggleChild = !this.toggleChild;
e.stopPropagation();
}
上面的代码工作正常,但是当我单击按钮时,整个孩子tr
展开了。我究竟做错了什么?我真正想要的是,当我单击按钮时,它只会扩展自己的孩子。