【发布时间】:2021-06-15 23:25:29
【问题描述】:
我有这个数组:
grp = [ {model: "CF650-3C", color: {Orange: 3, Black: 2} }, {model: "HD4533F", color: {Black: 2, Orange: 1} } ]
这些是其中具有 .model 和 .color 属性的对象,我想将它们显示在表格中,因此我需要单独访问其中的所有 .color 值。 到目前为止,我已经尝试过这样的迭代:
<table class="table table-striped" >
<thead>
<tr >
<th scope="col">Model</th>
<th scope="col">color</th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let g of grp">
<tr >
<td>{{ g.model }}</td>
<td>{{ g.color | json }}</td>
</tr>
</ng-container>
</tbody>
问题是这样显示,我不知道如何访问不同的 .color 键和值
CF650-3C { "Orange": 3, "Black": 2 }
HD4533F { "Black": 2, "Orange": 1 }
【问题讨论】:
标签: angular typescript dictionary nested iteration