我正在循環瀏覽json文件以在面板中顯示數據。但我在控制如何正確顯示數據方面遇到了一些麻煩。 這是從服務返回的json數據:在ng中顯示json文件錯誤對於
Object {Group1: Object,
Group2: Object}
JSON文件數據樣本:
{
"Group1": {
"name": "Group1List",
"dataFields": [..],
"dataQuery": {..},
"id": 1,
"title": "Group1",
"content": {..}
},
}
這是我的服務:
getGroupsData(){
return this._http.get('...')
.map((res:Response) => res.json())
}
Component.ts:
groups: Array<any> = [];
getGroups(){
this.groupService.getGroupsData().subscribe(
data => this.groups = data;
}
H TML:
<div dnd-sortable-container [sortableData]="groups" [dropZones]="['container-dropZone']">
<div class="col-sm3" *ngFor="let group of groups; let i = index" dnd-sortable [sortableIndex]="i" [dragEnabled]="dragOperation">
<div class="panel panel-primary" dnd-sortable-container [dropZones]="['widget-dropZone']">
<div class="panel-heading"></div>
<div class="panel-body"></div>
</div>
</div>
</div>
當我使我的代碼在控制檯中的錯誤,指出:在標題中Error trying to diff '[object Object]'
我想從JSON添加Group1
,然後在我身上會顯示不同部分。
問題的根源是什麼?
我同意你的看法,但是我不能改變json格式,並保持我的狀態。 – bluePearl
@bluePearl我已經更新了答案 –
,所以我在渲染時沒有得到錯誤,但是當我嘗試從json打印數據時,出現未定義的錯誤。 '{{group [i] .title}}' – bluePearl