[英]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.