将快照项目添加到阵列而无需循环或forEach

时间:2019-02-22 00:41:47

标签: google-cloud-firestore angularfire2

使用Firestore,我可以使用以下内容将项目分配给数组:

this.Svc.getCategories().valueChanges().subscribe(categories => {
  this.categories = categories;
})

但是,这会侦听项目的更改并将更改添加到数组中。

使用

this.Svc.getCategories().get().subscribe(categories => {
  categories.forEach(category => {
    this.categories.push(category.data())
  });
})

允许我将项目添加到数组中,而无需侦听更改。

但是,此方法要求我使用forEach或循环将数据推入数组。

有没有一种方法可以获取数据的一次性快照并将数据分配给数组,而无需循环和使用push()

1 个答案:

答案 0 :(得分:0)