我想从我的firebase收听一些数据,但我首先要检查是否已经创建了导致特定数据的密钥。如果它们还没有制作就没有问题,我不必听。
我收到此错误消息:
snip.child(...)。曾经不是一个函数
我试图从here跟踪他们的文件,看起来好像我在做什么应该是合法的。
.hasChild(...)
工作正常。
rootRef.child('match-feed-comments').once('value', snip => {
if (snip.hasChild(this.props.matchId)) { // Checking if child exists
snip.child(this.props.matchId).once('value', snup => { // if the child exists we listen
if (snup.hasChild(this.props.feedComponentId)) {
snup.child(this.props.feedComponentId).on('value', snap => {
// finally I want to do stuff with the data
this.setState({
comments: snap.val()
})
});
}
});
}
});