简体   繁体   English

遍历对象数组-* ngFor-Angular 6

[英]Iterate through Object array - *ngFor - Angular 6

Could some one tell me how to iterate below data structure. 有人可以告诉我如何在数据结构下进行迭代。 ii'm trying to load in normal bootstrap table. ii。试图加载到普通的引导表中。 but failed. 但失败了。 so far i tried to for..loop inside an for of loop. 到目前为止,我试图for..loop内的for of循环。 but it returns undefined on ' tableData ' 但它在' tableData '上返回未定义

i know its silly and duplicate question. 我知道它的愚蠢和重复的问题。 but i don't find solution. 但我找不到解决方案。

{
"parent":{  
      "tableHeading":{  
         "Header1":"ASD",
         "Header2":"QQQ",
         "Header3":"YYY",
         "Header4":"OOO",

      },
      "tableData":[  
         {  
            "Sample_1":"2019-08-19T00:00:00",
            "Sample_2":"Johney",
            "Sample_3":"30",
            "Sample_4":"PA,

         },
         {  
            "Sample_1":"2019-08-19T00:00:00",
            "Sample_2":"Allen P",
            "Sample_3":"29",
            "Sample_4":"SA",

         },
         {  
            "Sample_1":"2019-08-19T00:00:00",
            "Sample_2":"Chris",
            "Sample_3":"28",
            "Sample_4":"MM",

         }
      ]
   }
}

Try like this: 尝试这样:

<table border="1">
    <tr>
        <td *ngFor="let head of data.parent.tableHeading |keyvalue">
            {{head.value}}
        </td>
    </tr>
    <tr *ngFor="let item of data.parent.tableData">
        <td *ngFor="let element of item | keyvalue">
            {{element.value}}
        </td>
    </tr>
</table>

Working Demo 工作演示

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

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