小编Mar*_*ork的帖子

如何使用 Angular Firestore 创建和更新子集合?

我在 Firestore 中创建了一个集合“Person”。我能够从代码创建文档和字段。

ngOnInit() {
this.personCol = this.afs.collection('person');
//snapshotChanges is used to retreive the document data and other metadata, which includes the ID
//we need ID to edit or delete a record
this.person = this.personCol.snapshotChanges()
  .map(actions => {
   return actions.map(a => {
     const data = a.payload.doc.data() as Person;
     const id = a.payload.doc.id;
     return { id, data };
   });
  });}
addPerson() {
this.afs.collection('person').add({
  'name': this.name,
  'age': this.age,
});}
getPerson(PersonId) {
this.personDoc = this.afs.doc('person/'+personId);
this.singlePerson = this.personDoc.valueChanges();
Run Code Online (Sandbox Code Playgroud)

}

现在我想添加该人借阅的书籍列表:

Person: 
{Name: "John" …
Run Code Online (Sandbox Code Playgroud)

javascript angularfire2 angular google-cloud-firestore

4
推荐指数
1
解决办法
3844
查看次数