如何遍历Json Object中的多个Arrays

时间:2017-04-04 04:06:26

标签: arrays json angular

我试图在json对象中循环遍历多个数组。 这是json对象结构的图片。

enter image description here

我一直在尝试使用ngFor循环,但是我收到了错误。以下是我试图循环的代码:

<ion-item *ngFor="let item of items">
{{conversation}}
 </ion-item>

我收到以下错误:

caused by: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.

我需要能够循环遍历所有数组,但我无法弄清楚如何做到这一点。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

// in component.ts
data = [];
constructor() {
  for (let item of Object.keys(your_object)) {
    this.data.push(your_object[item]);
  }
}

// in component's template
<ul>
  <li *ngFor="let d of data">
    <span *ngFor="let i of d">{{i}}</data>
  </li>
</ul>
相关问题