2017-04-04 99 views
-2

我想循环通过json对象内的多个数组。 这是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. 

我需要能够循环,但我可以”弄清楚如何做到这一点。任何帮助都感激不尽。

+0

这不是一个数组的数组,而是一个具有数组键的数组作为属性的数组。原始对象是如何生成的? –

+0

原始对象是通过API调用生成的,来自该API调用的数据以这种格式返回 – DN0300

+0

我非常确定ng-repeat被angular 2中的ngfor所取代? – DN0300

回答

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

我试过了,我得到这个错误'造成的:无法读取未定义的属性'键' – DN0300

+0

验证你的JSON似乎与JSON有关系问题 – mayur

+0

我做了Json似乎很好 – DN0300