显示数据角度4(将obj转换为数组)

时间:2017-11-06 08:19:40

标签: arrays angular ngfor

我正在尝试在一个阵列中显示一个物体的物体,因为我无法改变后端,所以我一直撞到墙上。 这是我到目前为止所得到的,M01,M02,M03 ...可能是指我们11月份有11个月,但是如果它是2月ID只有M01和M02。因为我得到了一个物体的属性,我不能在第二个循环它,我有很多麻烦它

Array to display

这是我的观点

<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>

1 个答案:

答案 0 :(得分:1)

我认为这会对你有所帮助:

从模板方面无法直接访问Object

您需要做的就是Object.keys TemplateComponent方式提供对// Component Side : objectKeys = Object.keys; // Template Side : <td *ngFor="let key of objectKeys(estado.M)"> Key: {{key}}, value: {{estado.M[key]}} </td> 方的访问权限。

class leave(models.Model): 
    date_created = models.DateTimeField(auto_now_add=True)

您可以阅读有关Object.keys HERE

的更多信息