угловой первенг динамических колонн - PullRequest
0 голосов
/ 27 июня 2018

У меня проблема с получением данных для моих динамических столбцов с помощью PrimeNg. У меня следующая структура JSON:

enter image description here

Мой Component.ts выглядит так:

this.claimOverviewService.getCarClaimOverview(this.domain).then(claimOverview => {
  this.carClaimOverview = claimOverview;
  //console.log(this.carClaimOverview);
});

this.cols = [
  {field: 'id', header: 'VorgangsId', type: 'string'},
  {field: 'repairCosts', header: 'Reparaturkosten', type: 'number'},
  {field: 'status.name', header: 'Status', type: 'status'},
  {field: 'creationDate', header: 'Eingang', type: 'date'}
];

И мой Componjent.html выглядит так:

<p-table [columns]="cols" [value]="carClaimOverview" [paginator]="true" [rows]="10">
<ng-template pTemplate="header" let-columns>
  <tr>
    <th *ngFor="let col of columns" [pSortableColumn]="col.field">
      {{col.header}}
      <p-sortIcon [field]="col.field"></p-sortIcon>
    </th>
  </tr>
</ng-template>
<ng-template pTemplate="body" let-claim let-columns="columns">
  <tr>
    <td *ngFor="let col of columns">
      <span *ngIf="col.type !== 'date'">
        {{claim[col.field]}}
      </span>
      <span *ngIf="col.type === 'date'">
        {{claim[col.field] | date:'fullDate'}}
      </span>
    </td>
  </tr>
</ng-template>

Мой Datatable выглядит так: enter image description here Как видите, столбец статуса не отображается. Мой массив cols получил поле 'status.name', но имя не появляется. Если я помещаю статус в поле, я получаю [объект объекта] в моей таблице данных. enter image description here

Таким образом, поле не обнаруживает подобъекты моего json. Есть ли возможность показать мои подобъекты или дать возможность полю знать, что под ними лежит объект?

1 Ответ

0 голосов
/ 27 июня 2018

Просто измените поле на claim[col.field]?.name.

Заменить cols объекта из

 {field: 'status.name', header: 'Status', type: 'status'},

к этому

 `{field: 'status', header: 'Status', type: 'status'},`
...