如何为firestore.collection.doc(id).delete()创建条件子句

时间:2019-06-12 04:16:14

标签: angular typescript firebase google-cloud-firestore ionic4

我有一个带有项目列表的离子页面。当我删除项目时,我必须离开页面,然后返回以查看该项目已被删除。我可以在数组中搜索要删除的项目,但我不知道如何根据条件删除它。

async removeItinerary(id) {
      const actionSheet = await this.actionSheetCtrl.create({
      header: 'Albums',
      buttons: [
        {
          text: 'Delete',
          role: 'destructive',
          icon: !this.platform.is('ios') ? 'trash' : null,
          handler: () => {
            return this.itineraryCollection.doc(id).delete();
          }
        },
        {
          text: 'Cancel',
          role: 'cancel', // will always sort to be on the bottom
          icon: !this.platform.is('ios') ? 'close' : null,
          handler: () => {
          }
        }
            ]
        });
        await actionSheet.present();
    }

我从组件中调用它:

  deleteItinerary(id: string) {
    this.dataSvc.removeItinerary(id);
  }

所以问题是,如果用户单击取消,我不想从集合中删除该项目。但是,如果他们单击删除,我想从阵列中删除该项目。最好的方法是什么?

感谢您的帮助

0 个答案:

没有答案