【发布时间】:2021-11-02 06:58:24
【问题描述】:
我有一个对象数组,在每个对象内我都有一个对象数组。我想将那些内部对象数组(清单和权重)填充到表中。我得到的是,我可以填充对象数组,并且内部数组不显示每个行跨度。 附上我的输出和预期的输出图像 1: https://i.stack.imgur.com/DqYtD.png [2]:https://i.stack.imgur.com/vqVjs.png
HTML code;
<table class="table table-xs table-sm table-hover">
<thead class="table-primary">
<tr>
<th width="20%">Activity Name</th>
<th width="15%">Activity Description</th>
<th width="15%">Overall Percentage</th>
<th width="10%">CheckList</th>
<th width="10%">Weightage</th>
</tr>
</thead>
<tbody>
<ng-container formArrayName="activity_mappings" *ngFor="let activity of activityMappings['controls']; let i = index;">
<ng-container [formGroupName]="i">
<tr>
<td>
<input type="text" class="form-control form-control-sm" placeholder="Activity Name"
formControlName="activity_name"/>
</td>
<td>
<input type="text" class="form-control form-control-sm" placeholder="Description"
formControlName="description"/>
</td>
<td>
<input type="text" class="form-control form-control-sm" placeholder="Overall Percentage"
formControlName="overall_percentage"/>
</td>
<ng-container formArrayName="check_lists" *ngFor="let ch of activity.check_lists;let checkListindex = index;">
<ng-container [formGroupName]="checkListindex">
<ng-container *ngIf="checkListindex > 0">
<td>
<input type="text" class="form-control form-control-sm" placeholder="CheckList" formControlName="check_list_title"/>
</td>
<td>
<input type="text" formControlName="weightage" class="form-control form-control-sm" placeholder="Weightage"/>
</td>
</ng-container>
</ng-container>
</ng-container>
</tr>
</ng-container>
</ng-container>
<tr *ngIf="activityMappings.length == 0">
<td class="text-center" colspan="4">No Activities Found</td>
</tr>
</tbody>
</table>
示例对象:
activity_mappings ": [ { "
activity_name ": "
testing ", "
description ": "
som text ", "
overall_percentage ": 80, "
check_lists ":[ { "
check_list_title ": "
Done ", "
weightage ": "
20 " } ] }, { "
activity_name ": "
playing ", "
description ": "
some text ", "
overall_percentage ": 30, "
check_lists ":[ { "
check_list_title ": "
Not Done ", "
weightage ": "
30 " } ] } ]
【问题讨论】:
-
你能改写你的描述吗?此外,您可以添加一个实际的对象数组来代替图像。
-
"activity_mappings": [ { "activity_name": "testing", "description": "som text", "overall_percentage": 80, "check_lists":[ { "check_list_title": "Done" , "weightage": "20" } ] }, { "activity_name": "playing", "description": "some text", "overall_percentage": 30, "check_lists":[ { "check_list_title": "Not Done" , "weightage": "30" } ] } ] 只是想将此对象数组填充到表先生
-
另外,能不能加你在这里工作stackblitz.com方便调试
标签: javascript html node.js angular typescript