如何模拟在PrimeNG的datatable中选择的数据?
@Component({
selector: 'p-dataTable',
template: `...`
})
class MockDataTableComponent {
@Input() value;
@Input() selection;
@Output() selectionChange = new EventEmitter();
click( rows: number) {
this.selection = rows;
return this.selection;
}
}
@Component({
selector: 'data-table',
template: `<p-dataTable #datatable></p-dataTable>`
})
class MyTableComponent {
@ViewChild('datatable') datatable;
}
如何在PrimeNG中手动为模拟的选择设置值?我想为选择分配一个值,例如
this.selection[0]['name'] = "John Doe";
this.selection[0]['age'] = 30;
我该怎么做?
发布于 2016-10-24 02:32:20
只需将初始选择传递到<p-dataTable>
中即可。
@Component({
selector: 'p-dataTable',
template: `...`
})
class MockDataTableComponent {
@Input() value;
@Input() selection;
@Output() selectionChange = new EventEmitter();
click( rows: number) {
this.selection = rows;
return this.selection;
}
}
@Component({
selector: 'data-table',
template: `<p-dataTable [selection]="mockSelection" #datatable></p-dataTable>`
})
class MyTableComponent {
mockSelection = [];
constructor(){
this.mockSelection[0]={};
this.mockSelection[0]['name'] = "John Doe";
this.mockSelection[0]['age'] = 30;
}
@ViewChild('datatable') datatable;
}
https://stackoverflow.com/questions/40209418
复制相似问题