我正在使用以下代码订阅API调用:
this.af.database.list("URL")
.subscribe((lineList) => {
this.lineList = lineList;
this.fullLineList = lineList;
});
每当我在我的组件中访问this.lineList
时,this.fullLineList
也会发生变化。
如何存储存储lineList
且受this.lineList
更改影响的变量?
答案 0 :(得分:0)
使用slice()
,您可以创建列表的副本:
this.af.database.list("URL")
.subscribe((lineList) => {
this.lineList = lineList;
this.fullLineList = lineList.slice();
});
另见https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Array/slice