【发布时间】:2017-06-08 14:58:01
【问题描述】:
我在使用 PrimeNG DataTable 的 Angular 2 应用程序中遇到了一个非常奇怪的问题。可以使用[editable]"true" 语法更改我的DataTable 中的数据。
DataTable 中的数据称为 =inschrijvingen。
我正在做this.originalInschrijvingen = this.inschrijvingen 在用户更改数据之前创建一个“副本”,以便我可以在稍后阶段比较更改。但由于某种原因,DataTable 数据绑定到originalInschrijvingen 和inschrijvingen。
这是我的代码:
onRowSelectUser(event) { //This is a different DataTable than the editable DataTable
this.getGebruikerZijnInschrijvingen(res => {
this.createRoleID(res => {
let selectedIds = this.gebruikerZijnInschrijvingen.map(it => it.DefUnitID);
this.selectedInschrijvingen = this.inschrijvingen.filter(inv => selectedIds.indexOf(inv.ID) != -1);
this.originalInschrijvingen = this.selectedInschrijvingen;
})
})
}
【问题讨论】:
-
也许阅读编程中的参考资料会有所帮助。 en.wikipedia.org/wiki/Reference_(computer_science)
-
谢谢!我不知道它是引用而不是“复制”。谢谢!
-
@Pengyy 感谢您的回复,但我想我已经找到了答案 = Link
-
@Milan_w 好的,对我来说,我建议您避免使用该链接中提到的
json.parse和json.stringify的方式可能会导致问题。 -
@Pengyy 好的,我会调查您的解决方案!谢谢!
标签: angular typescript data-binding datatable