angular - 如何从 firebase.firestore.DocumentSnapshot 获取文档数据?
问题描述
我从 Firestore 获得文件,它的工作:
this.sub = this.beluginService.getBeluginById(this.personId)
.subscribe((documentSnapshot: firebase.firestore.DocumentSnapshot) => {
console.log(documentSnapshot.data());
}
我的服务:
getBeluginById(id: string) {
return this.afs.collection('belugin').doc(id).get();
}
在 console.log 我得到一个对象:
{ id: "ya1jibU2pZx1niGiuAmp"
qwCF: [0, 0, 2, 0, 0, 6, 2]
qwCO: [0, 0, 0, 0, 2, 0, 0]
qwIMP: [10, 0, 2, 2, 2, 4, 0]
qwME: [0, 4, 0, 4, 2, 0, 0]
qwPL: [0, 0, 0, 0, 0, 0, 0]
qwRI: [0, 2, 2, 2, 2, 0, 0]
qwSH: [0, 0, 0, 0, 0, 0, 0]
qwTW: [0, 4, 4, 2, 2, 0, 8] }
但是当我尝试获取对象属性(等 id、qwCF)时:
this.sub = this.beluginService.getBeluginById(this.personId)
.subscribe((documentSnapshot: firebase.firestore.DocumentSnapshot) => {
this.id = documentSnapshot.data().id;
this.qwCF = documentSnapshot.data().qwCF;
}
我无法获取 data() 属性...。我的 VCCode 显示方法 data() 调用错误。为什么?
解决方案
如果documentSnapshot.data()
在日志中工作可能会从其中收集数据会更好:
const data = documentSnapshot.data();
this.id = data.id
可能取决于 ECMA 版本
this.id = data["id"];
推荐阅读
- string - Haskell - 使用递归替换字符串中的子字符串(在我的情况下不允许使用函数 take 和 drop)
- npm-install - 我应该怎么做才能让命令 npm install 工作?
- python - Python 列条目选择
- python - 通过 gRPC 调用 TkInter 时崩溃
- google-drive-api - 获取驱动器 api 中无配额文件的文件大小
- node.js - 如何为 HTTPS 打开我的后端 NodeJS 应用程序?
- testng - 质量保证 | 在 TestNg 监听器中获取场景标签
- node.js - 从 Firestore 数据库读取数据到自制网站
- java - 如何从另一个类访问用户定义的 List<> 值?
- python - 凯撒 Cyper Python