【问题标题】:PrimeNG p-dataView with not repeating FieldSetPrimeNG p-dataView 不重复 FieldSet
【发布时间】:2018-12-14 15:37:51
【问题描述】:

我正在使用 p-dataView,我想根据应用程序类型使用 p-fieldset,我想找到一种不重复字段集的方法。下面只是一种情况,我会以多个字段集结束。不确定最有效的方法是什么?基本上,我正在尝试将某些行分组以收集在一个字段集下。

例如:

<p-dataView [value]="someobject" [paginator]="true" [rows]="20">

    <ng-template let-prev let-rowIndexValue="rowIndex" pTemplate="listItem">

        <div class="container">
            <div class="row">
                <p-fieldset class="fieldset-auto-width" *ngIf="prev.app_type == 10">
                <p-header style="width:30px">Apps</p-header>
                    <div class="col-md-3">
                        <input type="checkbox" id="cbPreviewID" checked name="cbxPreview" (click)="togglePreviewApp($event,rowIndexValue)" style="margin-right:5px;margin-bottom:10px;margin-left:5px; margin-top:10px" [value]='prev.app_id'> {{prev.app_name}}
                    </div>

                    <div *ngIf="prev.roles.length>1" class="col-md-3" style="margin-right:5px;margin-bottom:10px;margin-left:5px; margin-top:10px">

                    <b>Role:</b> 
                    <select name="role" (ngModelChange)="selectedPreviewAppRole($event,rowIndexValue)" class="dropdown" style="width:85%" required [(ngModel)]="prev.seletedAppRoleID">
                        <option class="dropdown-item" value="" selected>Select</option>
                        <option class="dropdown-item" *ngFor='let role of prev.roles' [ngValue]="role.app_role_id">
                            {{role.app_role_name}}
                        </option>
                    </select>

                </p-fieldset>
            </div>  
        </div>                      
    </ng-template>                      
</p-dataView>

例如,测试 1 和 2 应该在 1 个被调用的字段集下,因为它们的(prev.app_type == 10")

现在我得到:

寻找:

【问题讨论】:

  • 它是由于 *ngIf="prev.app_type == 10"?。你可以尝试删除这个

标签: angular typescript primeng primeng-datatable


【解决方案1】:

尝试在 p-dataview 中包含 p-fieldset。它按预期工作。 *ngIf 条件可能有问题。

组件:

cars = [{
    id: 1,
    items: [{
      name: 'car1',
      description: 'this is car1 description'
    },{
      name: 'car2',
      description: 'this is car2 description'
    },{
      name: 'car3',
      description: 'this is car3 description'
    },{
      name: 'car4',
      description: 'this is car4 description'
    },{
      name: 'car5',
      description: 'this is car5 description'
    }]

}];

模板:

<p-dataView [value]="cars" [paginator]="true" [rows]="5">
  <p-header>List of Cars</p-header>
  <p-footer>Choose from the list.</p-footer>
  <ng-template let-car pTemplate="listItem">
      <p-fieldset legend="Header" *ngIf="car.id === 1" [toggleable]="true">
          <div *ngFor="let _car of car.items">
              {{_car.name}} - {{_car.description}}
          </div>
      </p-fieldset>
  </ng-template>
</p-dataView>

请参阅随附的屏幕截图。

【讨论】:

  • 我能够实现同样的事情,但问题就在那里,以你为例,我希望将汽车 1 和汽车 2 放在一个字段集下,其余的在一个字段集下
  • 我不想为每条记录重复字段集,所以我想使用 *ngIf="prev.app_type == 10" 来调整我的记录,所以如果 id 是 10 那么所有具有 10 的应用程序都应在一个字段集下..对于 if 11 等相同....
  • 任何想法!
  • 根据代码,它将显示在 2 个字段集 bcz 中,两者的值都为 10。而不是循环对象数组。您需要使用 apptype 及其对应的子级形成一个数组。 [{appType:10,孩子:[{name:'text1'},{name:'text2'}]]
  • 更新了答案。请检查。
猜你喜欢
  • 1970-01-01
  • 2019-08-13
  • 2022-01-05
  • 1970-01-01
  • 2018-12-11
  • 1970-01-01
  • 1970-01-01
  • 2017-11-06
  • 2018-12-07
相关资源
最近更新 更多