![](/img/trans.png)
[英]How to show string of array in the first column of primeng table in angular
[英]show array split in line breaks in primeng table
我正在使用角度7和primeng
在我的一个primeng表中,我得到一个表的列作为数组
permissions: ["api-search-miscellaneous", "api-show-miscellaneous", "api-updatestatus-miscellaneous",…]
0: "api-search-miscellaneous"
1: "api-show-miscellaneous"
2: "api-updatestatus-miscellaneous"
3: "api-delete-miscellaneous"
4: "api-add-miscellaneous"
5: "api-showall-miscellaneous"
6: "api-update-miscellaneous"
现在,primeng显示以逗号分隔的列,如何在一行中的不同行中一个接一个地显示数组元素。
这些是我的列,这里的权限是数组的形式,我在我的网页.ts文件代码中显示为组
this.cols = [
{
field: 'name',
header: this.getLocalTranslation(
'Features.gridLabel.featureGroup',
),
},
{
field: 'permissions',
header: this.getLocalTranslation(
'Features.gridLabel.functionalities',
),
},
];
.html文件代码
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr [pSelectableRow]="rowData">
<td *ngFor="let col of columns">
{{ rowData[col.field] }}
</td>
</tr>
</ng-template>
我得到了解决问题的方法
我将.ts代码更改为此代码,我使用了Angular切片管道并迭代了数组。
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr [pSelectableRow]="rowData">
<td *ngFor="let col of columns">
<div
*ngIf="
col.field == 'permissions';
then content;
else other_content
"
></div>
<ng-template #content>
<li *ngFor="let i of rowData[col.field] | slice: 0:i">
{{ i }}
</li></ng-template
>
<ng-template #other_content>{{
rowData[col.field]
}}</ng-template>
</td>
</tr>
</ng-template>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.