【问题标题】:How to repeat table <td></td> based on <th></th> in angular6如何在角度6中基于<the></th>重复表<td></td>
【发布时间】:2019-02-25 16:04:44
【问题描述】:

我有这两个数组

valuesArray=[{name:"abc",num:"111",status:"available"},
             {name:"def",num:"222",status:"available"},
             {name:"ghi",num:"333",ststus:"offiline"}]    
headerArray=[{headerName:"name"},{headerName:"num"}]

我想使用*ngFor 构造一个表,方法是让tds 与我的标题数组匹配。 请帮我解决这个问题。 提前致谢。

【问题讨论】:

标签: angular angular6


【解决方案1】:

试试这个,

<table>
    <thead>
        <tr>
            <!-- Iterate over headers -->
            <th scope="col" *ngFor="let header of headerArray;">
                 {{header.headerName}}
            </th>
        </tr>
    </thead>
    <tbody>
        <!-- Iterate over value rows -->
        <tr *ngFor="let valueRow of valuesArray">
            <!-- Iterate over headers -->
            <td *ngFor="let header of headerArray">
                <!-- Get required value by header as key -->
                {{valueRow[header.headerName]}}
            </td>
        </tr>
    </tbody>
</table>

【讨论】:

    猜你喜欢
    • 2019-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2012-03-09
    • 2016-01-08
    • 2019-05-06
    • 2017-10-17
    相关资源
    最近更新 更多