gpt4 book ai didi

javascript - 如何通过 Web 应用程序中的值从 firebase 数据库检索数据?

转载 作者:太空宇宙 更新时间:2023-11-04 15:26:44 24 4
gpt4 key购买 nike

我正在创建一个投诉门户,我想将 ID 分配给注册的人。我在 firebase 中的数据结构如下:

fir-web-learn-51ffc
complaint
-Kwe6QXol8DV-uMDxIe7:"Hiii"
-KweCaYQrgG75BiJW3dA:"Hooooo"

我已经使用此代码进行插入:

 function submitClick()
{
var complaint=document.getElementById('complaint').value;
var database=firebase.database().ref().child("complaint");
database.push().set(complaint);
}

对于上述代码,如何通过名称(Kwe6QXol8DV-uMDxIe7)的值(Hiii)检索名称。我已尝试过 Google Firebase 文档和 Youtube 上给出的代码,但没有成功。

最佳答案

您将通过 orderByValue 使用 Firebase 查询。所以像这样:

var ref=firebase.database().ref().child("complaint");   
ref.orderByValue().equalTo("Hiii").once("value", function(snapshot) {
snapshot.forEach(function(child) {
console.log(child.key);
});
});

除了查询本身之外,主要要注意的是回调中的 snapshot.forEach() 。需要此循环,因为查询可能会匹配多个结果。

关于javascript - 如何通过 Web 应用程序中的值从 firebase 数据库检索数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46790274/

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