代码之家  ›  专栏  ›  技术社区  ›  Idris.AH

Cloud firestore-向对象数组添加对象

  •  1
  • Idris.AH  · 技术社区  · 7 年前

    {
        address: "123"
        number: "456643634634634"
        postcode: "hshshs"
    }
    

    文件定义如下:

    userDocument : AngularFirestoreDocument<User>;
    this.userDocument = this.afs.collection('users').doc(`${this.userId}`);
    

    addCard(card: Card){
        this.userDocument.update({
            cards : firebase.firestore.FieldValue.arrayUnion(card)
        });
    }
    

    但是,在保存文档之前,我会出错,说:

    [ts]
    Type 'FieldValue' is not assignable to type 'Card[]'.
      Property 'length' is missing in type 'FieldValue'. [2322]
    user.model.ts(15, 5): The expected type comes from property 'cards' which is declared here on type 'Partial<User>'
    

    不知道怎么用 arrayUnion

    0 回复  |  直到 7 年前