这是我的代码:
var pushRef = currentAssignment.child('answers').push().catch(e => console.log('push', e));
pushRef.set({
// downloadURL: downURL,
textAnswer: textAnswer,
date: this.generateDate(),
seen: false,
// firebaseKey: pushRef.getKey(),
workKey: this.props.questionId
})
当我尝试运行它时,出现此错误:pushRef.set()
,但根据this part of the documentation在我看来,我所做的一切都是一样的。以下是 Google 的推送指令示例:
var postsRef = ref.child("posts");
var newPostRef = postsRef.push();
newPostRef
.set({
author: "gracehop",
title: "Announcing COBOL, a New Programming Language"
});
// we can also chain the two calls together
postsRef
.push()
.set({
author: "alanisawesome",
title: "The Turing Machine"
});
那么我错过了什么?
最佳答案
通过在 push()
后面添加 .catch(e => console.log('push', e))
,您可以将其从 firebase 数据库引用更改为某些内容别的。因此删除它可以解决这个问题。
据我所知,调用 push()
(不带参数)永远不会生成错误,它只会生成一个 Firebase 引用(唯一 key )客户端。
关于javascript - PushRef.set() 不是函数,Firebase 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50839819/