“finalResult”: [ { “表名称”:“表_1”, “colCategories”:[ { “columnnnn”:“用户”, “值”:[ { “值”:“0” }, { “值”:“10” }, { “值”:“60” }, { “值”:“0” }, { “值”:“0” }, { “值”:“0” }, { “值”:“0” }, { “值”:“0” }, { “值”:“0” } ] }, { “列nnnn”:“标题1”, “值”:[ { “值”:“460” } ] }, { “columnnnn”:“金额”, “值”:[ { “值”:“10” }, { “值”:“100” }, { “值”:“50” } ] } ] }, { “表名称”:“表_2”, “colCategories”:[ { “columnnnn”:“用户”, “值”:[ { “值”:“07” }, { “值”:“10” } ] }, { “columnnnn”:“金额”, “值”:[ { “值”:“70” } ] }, { “columnnnn”:“用户1”, “值”:[ { “值”:“57” } ] }, { “columnnnn”: “列”, “值”:[ { “值”:“80” } ] }, { “columnnnn”:“第 2 列”, “值”:[ { “值”:“10” } ] } ] } ]</pre> <p>以下是HTML代码:</p> <pre class="brush:php;toolbar:false;"><div *ngFor="让 j 为 FinalResult;索引为i”类=“”>表名称:{{j.tableNamee}};<table class=“table table-bordered”> <正文></div></pre> <p>这里没有特定的ts代码。我只是按照上述格式数据操作,并尝试在HTML中应用循环。我做错了什么吗?</p> <p><strong>这是期望的输出:</strong> 期望的输出 <p><strong>这是我得到的当前输出:</strong> 当前输出 <p>任何帮助都不会令人感激!</p><第 类=“”范围=“col”; *ngFor="让 k of j.colCategories"> {{k.columnnnn}} </ng-容器> </tbody> </表> <div *ngFor=“让 m 个 k.values”> {{m.value}} </span></td> </ng-容器>
P粉5118967162023-09-01 09:17:50
你的HTML标记看起来很奇怪,因为你的<tr>
包含一个包裹<td>
的<div>
。我认为这就是导致你的问题的原因。
我没有尝试过,但你可以尝试将你的<table>
标记更改为以下内容:
<table class="table table-bordered"> <thead> <tr class=""> <th class="" scope="col" *ngFor="let k of j.colCategories"> {{k.columnnnn}} </th> </tr> </thead> <tbody> <tr class="" *ngFor="let k of j.colCategories"> <td class="" *ngFor="let m of k.values"> <div class=""> <span title="{{m.value}}"> {{m.value}} </span> </div> </td> </tr> </tbody> </table>