繁体   English   中英

Angular2在动态列中循环

[英]Angular2 Looping through dynamic columns

我正在使用* ngFor使用angular2构建动态表,如下所示,但是我看不到数据。 我不确定{{x [col]}}是否正确,知道吗?

<tr *ngFor="let x of exportList">
     <td *ngFor="let col of cols">
        {{x[col]}}
     </td>                      
 </tr>

您需要遍历内循环中的每一行。 尝试:

<tr *ngFor="let rows of exportList">
     <td *ngFor="let col of rows">
        {{col}}
     </td>                      
 </tr>
<tr *ngFor="let x of exportList">
     <td *ngFor="let col of x">
        {{col}}
     </td>                      
 </tr>

您只需要用x替换cols。 exportList包含对象的数量。因此,在x中,每个循环中将获得一个对象。使用object可以获取每个字段。

暂无
暂无

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

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