我有一个像这样的数组:
[[{"user":"1","nice":"0","sys":"1","CPU":"93","irq":"0"},
{"user":"1","nice":"0","sys":"1","CPU":"92","irq":"0"},
{"user":"1","nice":"0","sys":"1","CPU":"92","irq":"0"},
{"user":"1","nice":"0","sys":"1","CPU":"92","irq":"0"}],
[{"user":"0","nice":"0","sys":"0","CPU":"91","irq":"0"},
{"user":"0","nice":"0","sys":"1","CPU":"91","irq":"0"},
{"user":"1","nice":"0","sys":"0","CPU":"91","irq":"0"},
{"user":"0","nice":"0","sys":"0","CPU":"90","irq":"0"}]]
我希望使用ngFor循环遍历这个对象数组,并在HTML表格中显示它。
<table class="table table-striped mt-5">
<thead>
<tr>
<th scope="col">User</th>
<th scope="col">Nice</th>
<th scope="col">Sys</th>
<th scope="col">CPU</th>
<th scope="col">IRQ</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let post of posts">
<td>{{post.user}}</td>
<td>{{post.nice}}</td>
<td>{{post.sys}}</td>
<td>{{post.CPU}}</td>
<td>{{post.irq}}</td>
</tr>
</tbody>
</table>
但是我的代码没有运行
*ngFor="let post of posts[0]"
(未测试),但我认为您可以像这样访问嵌套数组。 - ghuntheur