Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 已更改的子事件firebase_Node.js_Express_Firebase_Firebase Realtime Database - Fatal编程技术网

Node.js 已更改的子事件firebase

Node.js 已更改的子事件firebase,node.js,express,firebase,firebase-realtime-database,Node.js,Express,Firebase,Firebase Realtime Database,我是firebase的新手。我只是在尝试一些例子,顺便说一句,我遇到了一些非常酷的事件 我在firebase数据库中保存了一些数据,该数据库是: driver -KV_Cj7sL6sg6K9E5ifh status: "Incomplete" 困扰我的是,当一个孩子被更新时,就会触发child_changed事件。当我访问它的数据时,我看不到钥匙 我在驱动程序表中创建了一个节点(我认为firebase中的一行称为节点,但不确定)。当我更改它的状态以完成它触发的子

我是firebase的新手。我只是在尝试一些例子,顺便说一句,我遇到了一些非常酷的事件

我在firebase数据库中保存了一些数据,该数据库是:

 driver
      -KV_Cj7sL6sg6K9E5ifh
         status: "Incomplete"
困扰我的是,当一个孩子被更新时,就会触发child_changed事件。当我访问它的数据时,我看不到钥匙

我在驱动程序表中创建了一个节点(我认为firebase中的一行称为节点,但不确定)。当我更改它的状态以完成它触发的子对象更改事件时。我收到了更新过的数据包。问题是我也想得到身份证(KV_Cj7sL6sg6K9E5ifh)。但问题是它只给我发送状态:完成

以下是我为child_编写的代码:

usersRef.on("child_changed", function(data) {
   var player = data.val();
   console.log(player);
   console.log("The new status is:  "+ player.status);
});

请帮助我,我将如何获得身份证了。谢谢

您可以获得Id儿童,请在下面尝试

console.log("The new status is:  "+ player.$id);
console.log("The new status is:  "+ data.ref.key); //it will returns -KV_Cj7sL6sg6K9E5ifh


console.log("The new status is:  "+ data.ref.parent.key); //it will returns driver
Firebase
返回的每个
对象
都包含
$id
属性

更新:

您可以获得
id/key
甚至
Firebase
在子级之间不返回id,请在下面尝试

console.log("The new status is:  "+ data.ref.key); //it will returns -KV_Cj7sL6sg6K9E5ifh


console.log("The new status is:  "+ data.ref.parent.key); //it will returns driver

你所谓的id,在Firebase术语中称为密钥。要获取快照的键,您可以访问该快照的
属性:

usersRef.on("child_changed", function(snapshot) {
   var player = snapshot.val();
   console.log(player);
   console.log("The new status is:  "+ player.status);
   console.log("The key of the player is "+snapshot.key);
})

扎伊德,这给了我一个不明确的答案。下面是我如何使用它的
usersRef.on(“child_changed”,function(data){var player=data.val();console.log(“新状态为:“+player.status”);console.log(“新Id为:”+player.Id);})
console.log(播放器)的输出是什么?Zaid它是未定义的范围,它给出的
console.log(播放器)
是未定义的?那么你是如何获得地位的。它不能是未定义的辅助玩家。状态给我完成,因为我已经将状态从未完成更改为完成,但玩家本身给我未定义。我知道。我试着用钥匙,但那对我不起作用。这才是真正让我惊讶的,因为我来到这里,弗兰克,就像你说的那样,它开始对我起作用了。我试图找出问题出在哪里,但没有发现任何错误。重新启动我的计算机,我得到了你告诉我的钥匙。真奇怪。很高兴听到你把它整理好了。交叉邮寄: