gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 20:54:43 26 4
gpt4 key购买 nike

我在 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();

}

现在我想添加一个人借的书的列表:

Person: 
{Name: "John"
Age: 32
Books: {Title: "First book", Author: "Some author"
Title: "Second book" Author: "Another author"},
{Name: "Anne"
Age: 21
Books: {Title: "How to... book", Author: "Author Name"
Title: "Flowers book" Author: "Another author"}

如何使用 Angular 创建 Books 子集合?我如何访问 Books 子集合以从代码更新 titleauthor

最佳答案

要访问特定人员的子集:

this.personBooks = this.afs.collection('person/'+personId+'/Books');

关于javascript - 如何使用 Angular Firestore 创建和更新子集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49899008/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com