Вяч*_*лав 4 firebase angular google-cloud-firestore
我从 Firestore 获取文档,它可以工作:
this.sub = this.beluginService.getBeluginById(this.personId)
.subscribe((documentSnapshot: firebase.firestore.DocumentSnapshot) => {
console.log(documentSnapshot.data());
}
Run Code Online (Sandbox Code Playgroud)
我的服务:
getBeluginById(id: string) {
return this.afs.collection('belugin').doc(id).get();
}
Run Code Online (Sandbox Code Playgroud)
在 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] }
Run Code Online (Sandbox Code Playgroud)
但是当我尝试获取对象属性(等 id、qwCF)时:
this.sub = this.beluginService.getBeluginById(this.personId)
.subscribe((documentSnapshot: firebase.firestore.DocumentSnapshot) => {
this.id = documentSnapshot.data().id;
this.qwCF = documentSnapshot.data().qwCF;
}
Run Code Online (Sandbox Code Playgroud)
我无法获取 data() 属性......我的 VCCode 显示方法 data() 调用错误。为什么?
如果documentSnapshot.data()在日志中工作可能会从中获取数据,那就更好了:
const data = documentSnapshot.data();
this.id = data.id
Run Code Online (Sandbox Code Playgroud)
可能取决于 ECMA 版本
this.id = data["id"];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7887 次 |
| 最近记录: |