【问题标题】:Ionic 4 firestoe how to save id in data?Ionic 4 firestoe如何在数据中保存id?
【发布时间】:2019-11-29 09:51:46
【问题描述】:

我需要将文档 ID 保存在集合中。意味着当用户保存数据时,它也会将文档 ID 与数据一起保存。谁能告诉我该怎么做。谢谢:)

  create() {
     // the user details are updated in firebase user list
     this.groupDetails = {
       groupname: this.Name,
       description: this.description,
       members: this.checked,
       messages: [],
       createdId: this.user.userId,
       createrName: this.user.username
     }
     console.log(this.groupDetails);
    // details are submitted to creatGroup function from groupProvider
     this.messageService.createGroup(this.groupDetails).then(resp => {
      console.log(resp);
      this.toast.show("Group Created");
      this.router.navigate(["/home"]);
     });

   }

  createGroup(groupDetails) {
    return this.angularFirestore.collection('Groups').add(groupDetails);
  }

【问题讨论】:

    标签: angular ionic-framework google-cloud-firestore


    【解决方案1】:

    如果有人有更好的答案,我现在就是这样做的,所以它也很棒

      createGroup(groupDetails) {
        return this.angularFirestore.collection('Groups').add(groupDetails).then(ref => {
          ref.set({ group_id: ref.id }, { merge: true }).then(() => {
          console.log("Group id is added");
          });
      })
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-02
      • 2020-07-23
      • 2019-07-25
      • 2020-01-31
      • 1970-01-01
      • 2018-09-04
      相关资源
      最近更新 更多