简体   繁体   English

如何将孩子的孩子与本地存储中的数据匹配(Firebase 实时数据库)

[英]How to Match Child of a child with data from local storage (Firebase Realtime Database)

My Database structure is like this我的数据库结构是这样的

数据库结构

I have made a qr code scanner which scan the qr then it match the data from Firebase realtime database in the data matches it go on next page and store that qr code value in local storage.我制作了一个二维码扫描仪,它扫描二维码,然后它与来自 Firebase 实时数据库中的数据相匹配,数据与下一页上的 go 相匹配,并将该二维码值存储在本地存储中。 But When I try to mach the data on next page like this:但是当我尝试像这样处理下一页上的数据时:

 var db= app.database() let machine_id = localStorage.getItem('machineid') //output = 8c96aa286f24(Accurate data on console) db.ref('/All_machines/Generator/').orderByKey().equalTo(machine_id).once("value", snapshot => { if (snapshot.exists()){ const userData = snapshot.val(); var snapshot= snapshot.child(machine_id).val(); console.log(userData); //Output: here i didn't get anything not even any error message on console } })

But When i Write the same code after changing database just take out the machine id from generator and write under All_Machines like this但是当我在更改数据库后编写相同的代码时,只需从生成器中取出机器 ID 并像这样在 All_Machines 下写入

在此处输入图像描述

and Change my code according to this then my code start working.并根据此更改我的代码,然后我的代码开始工作。 but when my machine id is under generator its not working.但是当我的机器 ID 在生成器下时,它不起作用。 code:代码:

 var db= app.database() let machine_id = localStorage.getItem('machineid') db.ref('/All_machines').orderByKey().equalTo(machine_id).once("value", snapshot => { if (snapshot.exists()){ const userData = snapshot.val(); var snapshot= snapshot.child(machine_id).val(); console.log(userData); } })

By Running this code i get all the data from Firebase Realtime database通过运行此代码,我从 Firebase 实时数据库中获取所有数据

//Output:- //输出:-

在此处输入图像描述

While calling the data from local storage let machine_id = localStorage.getItem('machineid') my data comes with a extra space like this ' 8c96aa286f24' this is the reason why my code was not working i updated the code like this.从本地存储调用数据时let machine_id = localStorage.getItem('machineid')我的数据带有一个额外的空间,例如“8c96aa286f24”,这就是我的代码无法正常工作的原因,我更新了这样的代码。

 var machine_id_2 = localStorage.getItem('machineid') var space = machine_id_2.split(" ") var machine_id_1 = space[1] db.ref('/All_machines/Generator/').orderByKey().equalTo(machine_id_1).once("value", snapshot => { if (snapshot.exists()){ const userData = snapshot.val(); var snapshot= snapshot.child(machine_id).val(); console.log(userData); } })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从本地存储 Firebase 实时数据库中匹配孩子的孩子 - Unable to match child of a child from local storage Firebase RealTime database 如何编写 firebase 实时数据库规则以匹配根文件夹子文件夹名称与新数据自定义 uid - how to write a firebase Realtime database rule to match root folder child folders name with New Data custom uid 如何从 firebase 实时数据库中获取不同孩子的值? - How to get values from different child in firebase realtime database? 如何从实时数据库中获取数据以从父母到孩子做出反应? - How to get data from realtime database to react from parents to child? 如何从 Firebase 数据库中获取孩子的数据? - How to get data from a child in Firebase Database? 从 firebase 实时数据库中单个孩子下的多个推送 ID 中检索数据 - Retrieve data from multiple push ids under a single child in firebase realtime database 如何用key删除firebase实时数据库子节点? - how to delete firebase realtime database child node with key? 如何在不转换为数组的情况下将数字添加为 firebase 实时数据库子项? - How to add number as firebase realtime database child without converting to array? 将新数据添加到特定子项时,如何使用 Cloud Functions 将数据写入 Firebase 实时数据库 - How to Write Data Into Firebase Realtime Database with Cloud Functions when new Data is added to a Specific Child 从 Firebase 实时数据库子项中获取单个事件 - Fetching Single Event From a Firebase Realtime Database Child
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM