doc.idにthis.idが等しい作ります

cononor96:

私は前の関数の代わりに、そこに私が持っているハードウェアに組み込まれた値からdoc.idするthis.id等しいかCONT IDを作りたいです。

私はこれを成し遂げるために正しい構文ではよく分かりません。

  addToCart(){
    this.db.firestore.collection('products')
    .where('tagid','==', "049a1092285e80")
    .get()
    .then(querySnapshot => {
            querySnapshot.forEach(function (doc) {
              const id = doc.id;
              //const data = doc.data;

                  console.log("debug 1  ",doc.id); // id of doc
                  console.log("debug 2  ", doc.data()); // data of doc
                  console.log("debug 3", id);
                  //return {id};
            }) // end of for each

            // want to make this.id = doc.id 
            this.id = "KCSx3JPeoerFmeH5zW7R";
                  this.productService.getOneProduct(this.id).subscribe(res => {
                  this.product = res;
                  this.product.id = this.id;
                  this.amount = this.cartService.getItemCount(this.id);
                  console.log('tag id', this.product.tagid);

                  this.cartService.addProduct(this.product);
                });
     });
  }
AlexanderFSP:

良い一日!

ただ、コンテキストを保存し、変更するには、矢印機能を使用idプロパティを:

querySnapshot.forEach(doc => { this.id = doc.id; }) 

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=376527&siteId=1