簡體   English   中英

遍歷對象數組-* ngFor-Angular 6

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

有人可以告訴我如何在數據結構下進行迭代。 ii。試圖加載到普通的引導表中。 但失敗了。 到目前為止,我試圖for..loop內的for of循環。 但它在' tableData '上返回未定義

我知道它的愚蠢和重復的問題。 但我找不到解決方案。

{
"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",

         }
      ]
   }
}

嘗試這樣:

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

工作演示

暫無
暫無

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

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