Primeng 数据表 4.3:未填充数组更改
Primeng Datatable 4.3: array changes not populated
我正在使用 primeng 4.3
我已经对这个 primeng 数据表进行了编码:
<p-dataTable [value]="quotes" [editable]="true">
<p-column *ngFor="let col of cols" [field]="col.field
[header]="col.header" [editable]="col.editable">
<ng-template let-col let-quote="rowData" pTemplate="editor">
<p-spinner size="30" [(ngModel)]="quote[col.field]" name="quote"</p-spinner>
</ng-template>
</p-column>
</p-dataTable>
问题出现在this.quotes
改变的时候。我的意思是,当在 this.quotes
上填充新数组时,数据表不会填充更改。
为了确保填充新数组,我正在使用:
this.quotes = Object.assign([], calculatedQuotes);
所以,我的意思是,每次 this.quotes
被分配时,它都有一个对新数组的新引用。
有什么想法吗?
我正在使用 primeng 4.3
Change Detection Table may need to be aware of changes in its value in
some cases such as reapplying sort. For the sake of performance, this
is only done when the reference of the value changes meaning a setter
is used instead of ngDoCheck/IterableDiffers which can reduce
performance. So when you manipulate the value such as removing or
adding an item, instead of using array methods such as push, splice
create a new array reference using a spread operator or similar.
所以你的方法是正确的 table:
this.quotes = Object.assign([], calculatedQuotes);
要向您的网格添加新项目,您可以使用展开运算符:
this.quotes = [...this.quotes , newObject];
我正在使用 primeng 4.3
我已经对这个 primeng 数据表进行了编码:
<p-dataTable [value]="quotes" [editable]="true">
<p-column *ngFor="let col of cols" [field]="col.field
[header]="col.header" [editable]="col.editable">
<ng-template let-col let-quote="rowData" pTemplate="editor">
<p-spinner size="30" [(ngModel)]="quote[col.field]" name="quote"</p-spinner>
</ng-template>
</p-column>
</p-dataTable>
问题出现在this.quotes
改变的时候。我的意思是,当在 this.quotes
上填充新数组时,数据表不会填充更改。
为了确保填充新数组,我正在使用:
this.quotes = Object.assign([], calculatedQuotes);
所以,我的意思是,每次 this.quotes
被分配时,它都有一个对新数组的新引用。
有什么想法吗?
我正在使用 primeng 4.3
Change Detection Table may need to be aware of changes in its value in some cases such as reapplying sort. For the sake of performance, this is only done when the reference of the value changes meaning a setter is used instead of ngDoCheck/IterableDiffers which can reduce performance. So when you manipulate the value such as removing or adding an item, instead of using array methods such as push, splice create a new array reference using a spread operator or similar.
所以你的方法是正确的 table:
this.quotes = Object.assign([], calculatedQuotes);
要向您的网格添加新项目,您可以使用展开运算符:
this.quotes = [...this.quotes , newObject];