在primeng表中的换行符中显示数组拆分

时间:2019-05-16 06:43:24

标签: angular primeng

我正在使用定角7进行定焦

在我的一张primng表中,我得到了 表作为数组

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显示用逗号分隔的那列,我如何才能以不同的方式显示数组元素 仅排成一行。

这些是我的专栏,这里的权限是array的形式,我将以组的形式显示在我的网页上 .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>

enter image description here

1 个答案:

答案 0 :(得分:0)

我找到了解决问题的方法

我将.ts代码更改为此代码,我使用了Angular slice管道并遍历数组。

    <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>