【问题标题】:Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Array. json data找不到“object”类型的不同支持对象“[object Object]”。 NgFor 只支持绑定到诸如 Array 之类的 Iterables。 json数据
【发布时间】:2021-02-25 05:13:31
【问题描述】:

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]”。 NgFor只支持绑定Arrays等Iterables。下面是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); 能够在控制台中显示数据。

【问题讨论】:

  • 你能分享你为 ngFor 循环编写的代码吗?
  • [tool_order_id: "1",order_status_id: "10"] 这不是有效的 JS 数组语法。你确定你处理的是一个数组而不是一个对象吗?

标签: javascript json angular ionic-framework


【解决方案1】:

如果它以某种方式进入控制台,你可以在循环内循环

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

【讨论】:

  • 我有资产 [[mydata]] 和资产[mydata],我需要在单个变量中获取数据并以 HTML 格式显示。
【解决方案2】:

试试这样的

<ion-row *ngFor="let t of data">
<ion-row *ngFor="let tool of t.orders['assets']">

【讨论】:

    【解决方案3】:
    1. 数据格式不正确。 [ ] 表示一个数组。在数组中,您不能直接拥有键值对,[tool_order_id: "38",order_status_id: "10"]。它应该是一个对象{tool_order_id: "38",order_status_id: "10"}。首先确保您的数据格式正确。

    2. 请消除数据中的不一致,例如第 1 行的 assets 是一个数组数组,而第 2 行是一个数组。

      资产:[[tool_order_id:“38”,order_status_id:“10”]],

      资产:[tool_order_id:“1”,order_status_id:“10”],

    【讨论】:

      猜你喜欢
      • 2018-12-31
      • 2017-02-10
      • 2018-10-29
      • 2019-04-04
      • 2020-10-17
      • 2017-10-15
      • 2019-05-12
      • 2019-01-31
      相关资源
      最近更新 更多