angular5 - 如何将对象数据循环到表中?
问题描述
我有以下带有列和数据的对象。我想使用 *ngFor 显示列值。
到目前为止,我已经尝试了以下代码:
public productLists;
this.productLists = [];
this.productLists = this.loadProductLists();
html
<tr *ngFor="let column of productLists.columns">
<th scope="col">{{column}}</th>
</tr>
数据
columns:
action: "Action"
product_code_clip: "Product Code Clip"
product_name_clip: "Product Name Clip"
year: "Year"
__proto__: Object
data: (15) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
解决方案
您是否尝试过在您的列对象中迭代数据数组?
<tr *ngFor="let column of productLists.columns.data">
<th scope="col">{{column}}</th>
</tr>
推荐阅读
- mysql - 如何在查询中使用 if 条件?
- java - 当前状态完成或分派时无法获取请求或响应
- typescript - 在 Typescript 类中声明一个常量
- javascript - 注入秘密 api 密钥
- javascript - 每一侧的碰撞检测不起作用
- android - 购买高级版后如何防止对程序进行永久检查?
- python - 为什么保存在 python 中的 GIF 像素值会发生变化?
- publish-subscribe - 我怎样才能收到来自 google pubsub 的推送消息
- php - 如何将 id 添加到 $_SERVER["PHP_SELF"] 提交
- c++ - vcpkg + cmake + Visual Studio 不工作