gpt4 book ai didi

javascript - Firebase js库从非空数据库检索空数据

转载 作者:行者123 更新时间:2023-12-03 01:59:57 26 4
gpt4 key购买 nike

重现步骤:

将您的 Firebase 数据库初始化为:

{
"restaurants" : [ {
"address" : "via Rettifilo, 34 Castelguidone CH Italy",
"title" : "Dama & Dama"
}, {
"address" : "Corso Umberto I, 3 Castelguidone CH Italy",
"title" : "Bar sabatino"
} ]
}

检查您的读/写 Firebase 权限规则

{
"rules": {
".read": true,
".write": true
}
}

执行这段js代码:

firebase.inizializeApp(yourJsonConfig)
\*code*\
firebase.database().ref().once('value').then(function(snapshot){
console.log(snapshot.val()); \\ this will print Array(0)
})

预期行为:控制台日志"{'restaurants' ........}"

实际行为:控制台记录“Array(0)”,即没有数据!

我使用 firebase js 库(版本 4.13.1)。我哪里错了?

最佳答案

您需要使用 val() 方法返回数据。

 firebase.database().ref().once('value').then(function(snapshot){ 
console.log(snapshot.val());
})

编辑:那么您的问题存在于您未显示的另一段代码中。

检查这个例子:http://jsfiddle.net/zgfr91yd/

在控制台日志中:

enter image description here

并查看我的数据:

enter image description here

您需要为每家餐厅的家长提供唯一的 key 。您可以使用 Firebase 中的“推送”功能来实现此目的。

关于javascript - Firebase js库从非空数据库检索空数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50080794/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com