我有单个对象的JSON作为:

javascript - 在 Angular 中循环* ngFor时出错-LMLPHP

我通过调用component.ts文件中的API来获得此数据,如下所示

/* for auditgorup selecitonm */
this.http.get('http://localhost:8080/api/selections/getAllAuditGroupSelections')
  .subscribe((datas: any[]) => {
    this.auditSelection = datas;
    console.log(this.auditSelection);

    // You'll have to wait that changeDetection occurs and projects data into
    // the HTML template, you can ask Angular to that for you ;-)
    this.chRef1.detectChanges();

    // Now you can use jQuery DataTables :
    const tables: any = $('#nepal');
    this.dataTable = tables.DataTable();
  });


观点如下

<table id="nepal" class="table table-bodered">
  <thead>
    <tr>
      <th>Selection No</th>
      <th>SelectionDate</th>
      <th>SelectedBy</th>
      <th>PanEximNumber</th>
      <th>Name</th>
      <th>Address</th>
      <th>PhoneNumber</th>
      <th>SelectionType</th>
      <th>Group Desc</th>
    </tr>
  </thead>
  <tbody>
    <tr *ngFor="let nas of auditSelection">
      <td>{{nas.selectionId}}</td>
      <td>{{nas.selectionDate}}</td>
      <td>{{nas.selectedBy}}</td>
      <td>{{nas.panEximNumber}}</td>
      <td>{{nas.name}}</td>
      <td>{{nas.address}}</td>
      <td>{{nas.phoneNumber}}</td>
      <td>{{nas.selectionType}}</td>
      <td>{{nas.assignmentAudit.auditorGroup.groupDesc}}</td>
    </tr>
  </tbody>
</table>


<td>{{nas.assignmentAudit.auditorGroup.groupDesc}}</td>的最后一行中,我无法获得所需的值。

输出显示应为“ g1”。

最佳答案

我无法发表评论,因此请在此处添加。 assignmentAudit是一个数组,因此请尝试使用索引进行访问

关于javascript - 在 Angular 中循环* ngFor时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53256308/

10-10 21:54