这是我得到的数据格式。如何显示所有键名(即key1,key2,key3 ...)以及子键(即subkey1_1,subkey1_2 ...)及其值?
Array_main=[
{"key1":[
{"subkey1_1":
{"key1":"value1","key2":"value2"}
},
{"subkey1_2": {"ky1":"value1","ky2":"value2"}
},
]
},
{"key2":[
{"subkey2_1":
{"key1":"value1","key2":"value2"}
},
{"subkey2_2": {"key1":"value1","key2":"value2"}
},
]
]},
{"key3":[]},
......
];
如果我使用类似的东西:
<ion-list>
<ion-card *ngFor = "let array of array_main">
<ion-item>
<h2 >{{ array}}</h2>
</ion-item>
但我在HTML视图中获取[object Object]。如何解析内部对象并在ionic2中显示其键和值?
我使用了管道,但它将键显示为数字而不是我希望它们显示为键名...
import { Pipe, PipeTransform} from '@angular/core';
@Pipe({
name: 'pipe'
})
export class ObjectValuesPipe implements PipeTransform {
transform(obj: any) {
let result = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
result.push(key);
}
}
return result;
}
}
<ion-list>
<ion-card *ngFor = "let array of array_main | pipe">
<ion-item>
<h2 >{{ array}}</h2>
</ion-item>
输出为0,1,2 ......而我希望它像......“key1”,“key2”......