显示数据 angular 4(将 obj 转换为数组)
display data angular 4 (converting obj to array)
我试图在数组中显示一个对象的一个对象,我一直在用头撞墙,因为我无法更改后端。
这是我到目前为止得到的,M01、M02、M03... 可能指的是几个月,因为我们是 11 月,有 11 个,但是如果是 2 月,则只有 M01 和 M02。因为我得到了一个对象的 属性,所以我不能在一秒钟内循环它,而且我在使用它时遇到了很多麻烦
这是我的看法
<div *ngIf="estados" class="table-responsive col-lg-12 tablilla">
<table class="table table-bordered table-striped table-responsive">
<thead>
<tr>
<th></th>
<th *ngFor="let month of listaMonthsNames">{{month}}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let estado of estados">
<td>{{estado.nom_item}}</td>
<td *ngFor="let month of estado.M[0]">{{month}}</td>
</tr>
</tbody>
</table>
</div>
我想这对你有帮助:
没有从模板端访问 Object
的直接方法,因此,
您需要做的就是通过这种方式从 Component
提供 Object.keys
对 Template
端的访问:
// Component Side :
objectKeys = Object.keys;
// Template Side :
<td *ngFor="let key of objectKeys(estado.M)">
Key: {{key}}, value: {{estado.M[key]}}
</td>
您可以阅读更多关于 Object.keys HERE
我试图在数组中显示一个对象的一个对象,我一直在用头撞墙,因为我无法更改后端。 这是我到目前为止得到的,M01、M02、M03... 可能指的是几个月,因为我们是 11 月,有 11 个,但是如果是 2 月,则只有 M01 和 M02。因为我得到了一个对象的 属性,所以我不能在一秒钟内循环它,而且我在使用它时遇到了很多麻烦
这是我的看法
<div *ngIf="estados" class="table-responsive col-lg-12 tablilla">
<table class="table table-bordered table-striped table-responsive">
<thead>
<tr>
<th></th>
<th *ngFor="let month of listaMonthsNames">{{month}}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let estado of estados">
<td>{{estado.nom_item}}</td>
<td *ngFor="let month of estado.M[0]">{{month}}</td>
</tr>
</tbody>
</table>
</div>
我想这对你有帮助:
没有从模板端访问 Object
的直接方法,因此,
您需要做的就是通过这种方式从 Component
提供 Object.keys
对 Template
端的访问:
// Component Side :
objectKeys = Object.keys;
// Template Side :
<td *ngFor="let key of objectKeys(estado.M)">
Key: {{key}}, value: {{estado.M[key]}}
</td>
您可以阅读更多关于 Object.keys HERE