【发布时间】:2019-12-03 16:57:16
【问题描述】:
我必须通过使用 rowspan 进行分组来显示 HTML 表中的一些数据。 以下是预期的 GUI
我有如下 JSON 数据。 JSON数据here
角度代码
<table class="table table-fixed" border="1">
<thead>
<tr>
<th>Country</th>
<th>State</th>
<th>City</th>
<th>Street</th>
<th>Male</th>
<th>Female</th>
<th>Others</th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let country of Countries">
<tr *ngFor="let item of [].constructor(country.NoOfStreets); let streetIdx = index">
<ng-container *ngFor="let state of country.States; let stateIdx = index">
<td [attr.rowspan]="state.NoOfStreets" style="width: 15%">
{{state.StateName}}
</td>
</ng-container>
<ng-container *ngFor="let state of country.States; let stateIdx = index">
<ng-container *ngFor="let city of state.Cities; let cityIdx = index">
<td [attr.rowspan]="city.NoOfStreets" style="width: 15%">{{city.CityName}}</td>
<ng-container *ngFor="let street of city.Streets; let streetIdx = index">
<td style="width: 15%">{{street.StreetName}}</td>
<td style="width: 15%">{{street.Male}}</td>
<td style="width: 15%">{{street.Female}}</td>
<td style="width: 15%">{{street.Others}}</td>
</ng-container>
</ng-container>
</ng-container>
</tr>
</ng-container>
</tbody>
</table>
我无法生成预期的 UI。我得到了不同的用户界面并且没有正确呈现。我尝试了这个几乎一个星期,但没有任何结果。
PLUNK 版本是https://next.plnkr.co/edit/5nYNZ86BiWDke3GE?open=lib%2Fapp.ts&deferRun=1
【问题讨论】:
-
从 REST 调用接收的数据是否可能?我似乎只能找到人们发布关于使用静态数据执行此操作的信息,所以我很困惑这是否不可能,或者人们只是不知道该怎么做?
标签: html angular html-table