简体   繁体   English

DataTable中的primeNg复选框绑定对象

[英]primeNg Checkbox binding object in Datatable

https://www.primefaces.org/primeng/#/checkbox https://www.primefaces.org/primeng/#/checkbox

In the below code I am trying to get the checkboxes to add objects to an array that is in model driven form with the variable name of selectedComponents. 在下面的代码中,我试图获取复选框以将对象添加到模型驱动形式的数组中,该数组的名称为selectedComponents。

So the object type of item1 below is CampaignProductModel and that is an array called selectedComponents in my model for the form. 因此,下面item1的对象类型是CampaignProductModel,在我的表单模型中,这是一个名为selectedComponents的数组。

I am having trouble binding and added of all checked items to the array in my model object. 我在绑定时遇到麻烦,并将所有检查的项目添加到了模型对象中的数组中。

 <p-dataTable *ngIf="perviousCampaignProduct" [value]="perviousCampaignProduct" #dt [responsive]="true" filter="filter" [rows]="25" [paginator]="true" selectionMode="single" [(selection)]="selectedItem" [contextMenu]="cm">
    <p-header>Pervious Campaign Products </p-header>
    <p-column header="Images">
        <template let-item="rowData" pTemplate="body">
          <img style="max-height:150px;" src="http://cdnll.somesite.com/images/1000/{{item.itemSku}}.jpg" />
        </template>
    </p-column>
    <p-column field="itemSku" header="Item" [filter]="true" filterMatchMode="contains" filterPlaceholder="Search"></p-column>
    <p-column field="components" header="Components">
       <template let-item="rowData" let-col pTemplate="body">
          <ul style="list-style: none;">
             <li *ngFor="let item1 of item[col.field]">
                <p-checkbox value="item1" formControlName="selectedComponents" label="{{item1.itemSku}}"></p-checkbox>
             </li>
          </ul>
       </template>
     </p-column>
  </p-dataTable> 

Goal 目标

Added all check items from p-checkbox as objects to an array in my model driven form. 将p-checkbox中的所有检查项目作为对象添加到我的模型驱动形式的数组中。

Tried: 尝试过:

value="{{item1}}"

... knew it won't work ...知道这行不通

It´sa bit later but i think this can resolve your problem Change this code: 稍后,但是我认为这可以解决您的问题更改此代码:

 <p-checkbox value="item1" formControlName="selectedComponents" label="{{item1.itemSku}}"></p-checkbox>

for this one: 为此:

 <p-checkbox [value]="item1" formControlName="selectedComponents" [label]="item1.itemSku"></p-checkbox>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM