我在ng2-smart-table中有一个“状态”列,并且我正在使用renderComponent显示一个复选框。事实是,我不知道如何检索状态(真或假)以选中或取消选中该复选框。使用* ngFor,它将在表的每一行中显示所有值:image with the problem
代码在模板上看起来像这样:<nb-checkbox *ngFor="let item of data" (checkedChange)="toggle($event)" [checked]="item['status']">{{isWorking}}</nb-checkbox>
在component.ts上:
export class ToggleComponent implements OnInit {
checked = false;
isWorking: string = 'OFF';
data: any[];
constructor(private service: SmartTableService) {}
ngOnInit() {
this.data = this.service.getData();
}
toggle(checked: boolean) {
this.checked = checked;
}
}
这是数据示例:
data = [{
device: 'SpainIAP',
type: 'IAP',
serialNumber: '123N',
status: true,
}, {
device: 'UKIAP',
type: 'IAP',
serialNumber: '123N',
status: false,
}, {
device: 'USAIAP',
type: 'IAP',
serialNumber: '123N',
status: false,
}];