Javascript 在*ngFor中循环时出错
我将单个对象的JSON表示为: 我通过调用Javascript 在*ngFor中循环时出错,javascript,angular,angular6,Javascript,Angular,Angular6,我将单个对象的JSON表示为: 我通过调用component.ts文件中的API获得了这些数据,如下所示 用于auditgorup Seleciton的/**/ this.http.get('http://localhost:8080/api/selections/getAllAuditGroupSelections') .subscribe((数据:any[])=>{ this.auditSelection=数据; console.log(this.auditSelection); //您必
component.ts
文件中的API获得了这些数据,如下所示
用于auditgorup Seleciton的/**/
this.http.get('http://localhost:8080/api/selections/getAllAuditGroupSelections')
.subscribe((数据:any[])=>{
this.auditSelection=数据;
console.log(this.auditSelection);
//您必须等待changeDetection发生并将数据投影到
//HTML模板,您可以要求为您提供;-)
this.chRef1.detectChanges();
//现在您可以使用jQuery数据表:
const tables:any=$(“#nepal”);
this.dataTable=tables.dataTable();
});
观点如下
选择号
选择日期
选择人
PanEximNumber
名称
地址
电话号码
选择类型
组描述
{{nas.selectionId}
{{nas.selectionDate}
{{nas.selectedBy}
{{nas.panEximNumber}
{{nas.name}
{{nas.address}
{{nas.phoneNumber}
{{nas.selectionType}
{{nas.assignmentAudit.auditorGroup.groupDesc}
在{{nas.assignmentAudit.auditorGroup.groupDesc}}
的最后一行,我无法获得所需的值
输出显示应为“g1”。我无法发表评论,因此将其添加到此处。assignmentAudit是一个数组,因此请尝试使用索引访问,我无法评论,因此请将其添加到此处。assignmentAudit是一个数组,因此请尝试使用索引访问
groupDesc
在auditorGroup
循环中,因此您无法在循环中获取值。试试看
<!-- Angular -->
<ul>
<li *ngFor="let item of nas.assignmentAudit.auditorGroup;">
</li>
</ul>
-
或者
{nas.assignmentAudit.auditorGroup[0].groupDesc}
groupDesc
在auditorGroup
循环内,所以您不能在循环内获取值。试试看
<!-- Angular -->
<ul>
<li *ngFor="let item of nas.assignmentAudit.auditorGroup;">
</li>
</ul>
-
或者
{nas.assignmentAudit.auditorGroup[0].groupDesc}
根据对JSON结构的分析,assignmentAudit
是一个数组
因此,您只能通过索引位置访问它
如果您确定assignmentAudit
是一个具有单个值的数组,则可以使用
<td>
{{nas.assignmentAudit[0].auditorGroup.groupDesc}}
</td>
根据对JSON结构的分析,
assignmentAudit
是一个数组
因此,您只能通过索引位置访问它
如果您确定assignmentAudit
是一个具有单个值的数组,则可以使用
<td>
{{nas.assignmentAudit[0].auditorGroup.groupDesc}}
</td>
那就行了。您试图访问的部分是一个数组。因此,选择第一个索引就可以定义它
那就行了。您试图访问的部分是一个数组。因此,选择第一个索引将根据您的屏幕截图定义它,
nas.assignmentAudit
指向一个数组,因此它应该是{nas.assignmentAudit[0]。auditorGroup.groupDesc
这将适用于您的nas.assignmentAudit[0].auditorGroup.groupDescrun内部循环。根据您的屏幕截图,nas.assignmentAudit
指向一个数组,因此它应该是{nas.assignmentAudit[0]。auditorGroup.groupDescrun
这将适用于nas.assignmentAudit[0]。auditorGroup.groupDescrun内部循环。因为您可以运行内部循环。因为您可以运行内部循环。