ngx datable将不显示行,仅显示列标题。 数据已更新,但未绑定到html中的行。
html:
<div class="columns">
<div class="column col-12">
<ngx-datatable
[rows]="rows"
[columns]="columns"
[rowHeight]="50">
</ngx-datatable>
</div>
</div>
打字稿:
export class CurrencyResultsComponent implements OnInit, OnChanges {
@Input() amount: number;
@Input() countryName: string;
@Input() rates: Rate[];
@Input() selectedcountry: string;
public columns = [
{ amount: 'Amount' },
{ name: 'Country' },
];
rows: DispRate[] = [];
constructor() {
}
ngOnInit() {
}
ngOnChanges(changes: SimpleChanges) {
if (changes.rates && changes.rates.currentValue !== changes.rates.previousValue) {
for (const key of Object.keys(this.rates)) {
const dataObj = {
'amount': this.rates[key] * this.amount,
'name': key
};
this.rows.push(dataObj);
}
}
}
}
预期:显示表格 实际:无数据可显示
答案 0 :(得分:0)
在this.rows=[...this.rows];
循环后添加for-of
,它将更新对ngx-table表行的绑定