javascript - 我正在尝试访问特定行,但在 Vue 中出现错误
问题描述
错误是Uncaught TypeError: snapShotChnaged.forEach is not a function
。我需要一个特定的行,这就是我使用文档的原因。
getAllDonations() {
firestore
.collection('donations')
.doc(this.$route.params.id)
.onSnapshot((snapShotChnaged) => {
this.donations = []
snapShotChnaged.forEach((donationDoc) => {
this.donations.push({
id: donationDoc.id,
name: donationDoc.data().name,
surname: donationDoc.data().surname,
class: donationDoc.data().class,
amount: donationDoc.data().amount
})
});
});
},
解决方案
您正在调用onSnapshot()
: DocumentReference
( ),因此(即您的对象)firestore.collection('donations').doc()
没有forEach()
方法。DocumentSnapshot
snapShotChnaged
一个人会在for sforEach()
的querySnapshot
返回值上使用。onSnapshot()
CollectionReference
您需要执行以下操作:
firestore
.collection('donations')
.doc(this.$route.params.id)
.onSnapshot(doc => {
const docData = doc.data());
// ....
});
推荐阅读
- javascript - 在前端注销时如何在浏览器中撤销 Http-only cookie?
- corda - Corda:节点启动期间的异常:证书现在立即无效
- ios - 标签未固定在表格视图单元格的右侧
- angular - Angular/Typescript:只读修饰符不起作用
- apache-spark - PySpark 窗口结束:有没有更好的方法来查找两列分区的行号
- java - 具有多个文件附加器的 Log4j2 json 配置
- aframe - 为自定义组件中的自定义属性设置动画
- javascript - 导航 json 文件以创建 jquery 自动完成所需的数组
- csv - 创建 Apache poi Workbook 时出现 Java 堆空间问题
- java - POS Hypercom Terminal T4230 使用 Java 串行端口通信的集成问题