angular - Primeng - 无法在列中显示数组项

标签 angular angular2-template primeng

我在 Angular 2 中使用 primeng datable。我的模型是一个产品数组。每个产品都有一组位置。该位置数组有一个属性 name 。如何在产品行中显示位置数组的每个名称

示例:如果第一个 product 在其 locations 数组中有 5 个 name,则它应在位置

目前我正在这样做。

<p-dataTable [value]="products" selectionMode="single" [(selection)]="selectedProduct" (onRowSelect)="onRowSelect($event)" [paginator]="true" rows="5" [responsive]="true">
              <p-column field="name" header="Name" [sortable]="true"></p-column>
              <p-column field="model" header="Model" [sortable]="true"></p-column>
              <p-column field="name" header="Quantity" [sortable]="true"></p-column>
              <p-column field="locations.location.name" header="Locations" [sortable]="true">
              </p-column>
            </p-dataTable>

最佳答案

您应该为该特定列使用 ngFor 检查下面的代码

<p-dataTable [value]="products" selectionMode="single" [(selection)]="selectedProduct" (onRowSelect)="onRowSelect($event)" [paginator]="true" rows="5" [responsive]="true">
              <p-column field="name" header="Name" [sortable]="true"></p-column>
              <p-column field="model" header="Model" [sortable]="true"></p-column>
              <p-column field="name" header="Quantity" [sortable]="true"></p-column>
              <p-column field="locations" header="Locations" [sortable]="true">
                    <ng-template let-col let-locations="rowData" let-ri="rowIndex" pTemplate="body">
                        <span *ngFor="let item of locations.location">{{item.name}} <br/></span>
                    </ng-template>
              </p-column>             
</p-dataTable>

关于angular - Primeng - 无法在列中显示数组项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43422858/

相关文章:

javascript - 如何从 Datepicker 中的代码更改时间?

angular - 我可以为angular2中的一个组件添加两个模板吗?

angular - Primeng pTooltip 循环

css - 如何在primeng中的卡住和解冻列表中设置不同的列样式和宽度

Angular 2获取路线没有路线提供者

angular - 绑定(bind)表达式不能在表达式 ANGULAR 7 的末尾包含链式表达式

angular - angular2 中的 Ng-repeat-start - 又名使用 NgFor 重复多个元素

typescript - 在 Typescript 中将一个对象映射到另一个对象

angular - 无法使用具有选择值的 patchValue 绑定(bind)到对象

angular - Tempus Dominus Bootstrap 4 更改语言/区域设置