简体   繁体   English

如何通过 angular 9 中 *ngFor 中的 json 值循环该组?

[英]How to loop this Group by json value in *ngFor in angular 9?

{
    "ABC 111": [
        {
            "id": 01,
            "valueOne": 50,
            "valueTwo": "string",
            "valuethree": "string"
        },
        {
            "id": 02,
            "valueOne": 50,
            "valueTwo": "string",
            "valuethree": "string"
        }
    ],
    "XYZ 222": [
        {
            "id": 01,
            "valueOne": 50,
            "valueTwo": "string",
            "valuethree": "string"
        },
        {
            "id": 02,
            "valueOne": 50,
            "valueTwo": "string",
            "valuethree": "string"
        }
    ]

}

The error is: Cannot find a differ supporting object '[object Object]' of type 'object'.错误是:找不到支持 object '[object Object]' 类型为 'object' 的不同。 NgFor only supports binding to Iterables such as Arrays. NgFor 仅支持绑定到 Iterables,例如 Arrays。

You don't need to change anything in .ts file.您无需更改.ts文件中的任何内容。 Change only inside the html .仅在html内部进行更改。

Assume you have responseObj .假设您有responseObj

  <div *ngFor="let obj of responseObj | keyvalue">
        <div *ngFor="let item of obj.value">
            {{item.id}}
        </div>
    </div>
    

在此处输入图像描述 i solved this prob on this url我在这个 url 上解决了这个问题

code代码

appUrl应用网址

please check请检查

<div *ngFor="let obj of  tesObj ">
        <div *ngFor="let item of obj">
          {{item|json}}
        </div>
</div>

it ts File它的 ts 文件

tesObj=Array.from(Object['values'](this.originalObj))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM