primeng p-column获得p-radioButton值

时间:2017-12-08 09:57:22

标签: angular primeng

我的.ts中有一个数组

 this.cars = [{ 'id': '1', 'vin': 't2se111' }, { 'id': '2', 'vin': 'tse' }, { 'id': '3', 'vin': 'tse22' }];

现在我将它显示为.html中的数据表

<p-dataTable [value]="cars" [editable]="true">
<p-column field="vin" header="人次" [editable]="true"></p-column>
<ng-template let-rowdata="rowData" pTemplate="body" field="test">
   <p-radioButton name="{{rowdata['id']+'record'}}" label="mylabe1" value="val1"></p-radioButton>
   <p-radioButton name="{{rowdata['id']+'record'}}" label="mylabe2" value="val2"></p-radioButton>
</ng-template>
</p-dataTable>

我可以轻松编辑汽车中的vin值,但我怎样才能获得radioButton的值?

我试过

this.cars = [{ 'id': '1', 'vin': 't2se111' ,'col':'val1'}, { 'id': '2', 'vin': 'tse' ,'col':'val2'}, { 'id': '3', 'vin': 'tse22','col':'val1' }];

和.ts

<p-dataTable [value]="cars" [editable]="true">
<p-column field="vin" header="人次" [editable]="true"></p-column>

<ng-template let-rowdata="rowData" pTemplate="body" field="col">
   <p-radioButton name="{{rowdata['id']+'record'}}" label="mylabe1" value="val1"></p-radioButton>
   <p-radioButton name="{{rowdata['id']+'record'}}" label="mylabe2" value="val2"></p-radioButton>
</ng-template>

但我失败了,任何人都可以教我怎么做吗?

1 个答案:

答案 0 :(得分:0)

最后我找到了

this.cars = [{ 'id': '1', 'vin': 't2se111' ,'col':'val1'}, { 'id': '2', 'vin': 'tse' ,'col':'val2'}, { 'id': '3', 'vin': 'tse22','col':'val1' }];

和html

<ng-template let-rowdata="rowData" pTemplate="body">
  <p-radioButton name="{{'record'+rowdata['id']}}" label="label1" value="val1" [(ngModel)]="rowdata.test"></p-radioButton>
  <p-radioButton name="{{'record'+rowdata['id']}}" label="label1" value="val2" [(ngModel)]="rowdata.test"></p-radioButton>
</ng-template>

解决我的问题,请回答〜