angular - Primeng Datatable 4.3:未填充数组更改
问题描述
我正在使用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
解决方案
在某些情况下,例如重新应用排序,更改检测表可能需要知道其值的变化。为了性能起见,只有在值的引用发生变化时才这样做,这意味着使用 setter 而不是 ngDoCheck/IterableDiffers,这会降低性能。因此,当您操作值(例如删除或添加项)时,不要使用 push 等数组方法,而是使用扩展运算符或类似方法 splice 创建新的数组引用。
因此,您查看表格更改的方式是正确的:
this.quotes = Object.assign([], calculatedQuotes);
要将新项目添加到网格中,您可以使用扩展运算符:
this.quotes = [...this.quotes , newObject];
推荐阅读
- java - 为什么 void 方法不接受参数中的整数?
- github - Github 创建或更新文件失败,MIME 64 编码的 422 无效 Base64 编码
- sublimetext3 - 将文件移动到硬盘上的其他位置
- tensorflow2.0 - TensorFlow 2.0 中的分层注意力
- neo4j - 在 Neo4j 中,我的 Cypher 查询从最近加载的对象中提取数据,但不是指定的对象
- python - 在没有 root 访问权限的 Unix 服务器上安装 pip 和 numpy
- python - 从两个单独的字典打印到 .txt 文件
- jquery - 用jquery中的特定字符串替换innerhtml字符串
- swiftui-navigationlink - 从堆栈中解除目的地后,SwiftUI navigationLink 不起作用
- snowflake-cloud-data-platform - Snowflake - 如何检索当前执行过程的名称?