如何修复 ngx-datatable 行以便它们出现?
How to fix ngx-datatable rows so they will appear?
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);
}
}
}
}
预期:显示 table
实际:没有数据显示
在for-of
循环之后添加this.rows=[...this.rows];
,它将更新对ngx-datable
行的绑定
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);
}
}
}
}
预期:显示 table 实际:没有数据显示
在for-of
循环之后添加this.rows=[...this.rows];
,它将更新对ngx-datable