簡體   English   中英

找不到支持 object 類型為“object”的“[object Object]”的差異。 NgFor 僅支持綁定到 Iterables,例如 Array。 json 數據

[英]Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Array. json data

JSON 數據

data:[
   {
    assets:[[tool_order_id: "38",order_status_id: "10"]],
    order_info:[id: "1", order_type: "6",check: "1", current_Stage_id: "29"]
},
{
  assets:[tool_order_id: "1",order_status_id: "10"],
    order_info:[id: "2", order_type: "3",check: "1", current_Stage_id: "29"]
},  
{
    assets:[[tool_order_id: "8",order_status_id: "10"]],
    order_info:[id: "3", order_type: "3",check: "1", current_Stage_id: "29"]
},
{
  assets:[tool_order_id: "3",order_status_id: "10"],
    order_info:[id: "4", order_type: "3",check: "1", current_Stage_id: "29"]
}
]

如果我重復這個,我會收到錯誤。 找不到支持 object 類型為“object”的“[object Object]”的差異。 NgFor 只支持綁定到 Iterables 比如 Arrays 下面是 html

 <div *ngIf="orders['assets'].length != 0">
 <ion-row *ngFor="let tool of orders['assets']">
 <ion-col col-4>{{ tool.tool_order_id }}</ion-col>
 <ion-col col-4>{{ tool.order_status_id }}</ion-col>
  </ion-row>
<div *ngIf="orders['assets'].length != 0">
 <ion-row *ngFor="let tool of orders['assets']['0']">
 <ion-col col-4>{{ tool.tool_order_id }}</ion-col>
 <ion-col col-4>{{ tool.order_status_id }}</ion-col>
  </ion-row>

並在 data.ts 文件中按順序存儲數據this.orders = this.data; console.log(this.orders); this.orders = this.data; console.log(this.orders); 能夠在控制台中顯示數據。

如果它以某種方式進入控制台,你可以在循環內循環

<div ngbDropdownMenu aria-labelledby="dropdownMenuButton2" *ngFor="let pChannel  of channels"> 
              <div *ngFor="let channel of pChannel">
              <a class="dropdown-item" (click)="getVouchersByChannelId(channel.channelId)">  
                  {{ channel.channelName }}             
                </a> 
              </div> 
            </div>

嘗試這樣的事情

<ion-row *ngFor="let t of data">
<ion-row *ngFor="let tool of t.orders['assets']">
  1. 數據格式不正確。 [ ] 表示一個數組。 在數組中,您不能直接擁有鍵值對[tool_order_id: "38",order_status_id: "10"] 它應該是一個 object {tool_order_id: "38",order_status_id: "10"} 首先確保您的數據格式正確。

  2. 請消除數據中的不一致,例如第 1 行中的資產是 arrays 的數組,而第 2 行中它是一個數組。

    資產:[[tool_order_id: "38",order_status_id: "10"]],

    資產:[tool_order_id:“1”,order_status_id:“10”],

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM