gpt4 book ai didi

JavaScript:提醒实时数据库上的特定值

转载 作者:行者123 更新时间:2023-12-03 03:30:13 24 4
gpt4 key购买 nike

我一直在尝试实现以下目标,但我做不到

这是我的快照数据:screen

如果我想提醒 ada 的名字,我应该使用什么代码?

我用了这个,它返回未定义:

    if (user) {
// User is signed in.
alert('user signed')

// Get a reference to the database service
var database = firebase.database();

var query = firebase.database().ref("users");
query.once("value")
.then(function(snapshot) {


snapshot.forEach(function(childSnapshot) {
// key will be "ada" the first time and "alan" the second time
var key = childSnapshot.key.val;
// childData will be the actual contents of the child
var childData = childSnapshot.val();

alert(key);
});

但它不起作用,有什么建议吗?

错误图片:sce

note: completely new to JavaScript

最佳答案

docs ,就是

// key will be "ada" the first time and "alan" the second time
var key = childSnapshot.key;

不是 var key = childSnapshot.key.val;

关于JavaScript:提醒实时数据库上的特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46134545/

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