【发布时间】:2021-11-30 11:02:57
【问题描述】:
频段和天线的数量是动态的。我需要将这些数据显示在表格中。
active_bands_to_antennas = [
{
band: "Blue",
antennas: ["One", "Two" "Three"]
},
{
band: "Red",
antennas: ["Four", Five"]
}
]
模板:
<tr>
<th> </th>
<th *ngFor="let data of active_bands_to_antennas" [attr.colspan]="data.antennas.length">{{data.band}}</th>
<th> </th>
<th> </th>
</tr>
预期输出:
table, th, td {
border: 1px solid black;
}
<table>
<tr>
<td> </td>
<td colspan="3">Blue</td>
<td colspan="2">Red</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>One</td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
<td>Five</td>
<td> </td>
<td> </td>
</tr>
</table>
一切正常。除了波段显示在多行而不是仅一行(取决于波段的数量)。
电流输出:
table, th, td {
border: 1px solid black;
}
<table>
<tr>
<td> </td>
<td colspan="3">Blue</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td colspan="2">Red</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>One</td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
<td>Five</td>
<td> </td>
<td> </td>
</tr
</table>
这就是我实现“colspan”的想法的地方:Dynamic rowspan in angular
【问题讨论】:
标签: html angular html-table