【发布时间】: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