gpt4 book ai didi

javascript - Firebase 导入排序数据

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

我想从 Firebase 数据库导入排序数据。

举个例子:我有一家小公司,我需要导入所有雇主的数据。我是 owner_01,这意味着我必须导入其子 owner_uidowner_01 匹配的所有用户。

数据将在网站上使用,这意味着我将使用 javascript

这里有 JSON :

    {
"Owner_users" : {
"owner_01" : {
"email" : "owner_01@gmail.com",
"uid" : 123
},
"owner_02" : {
"email" : "owner_02@gmail.com",
"uid" : 12345
}
},
"Users" : {
"user_01" : {
"Email" : "asd@ghita.com",
"Name" : "asd",
"age" : 23,
"owner_uid" : 123,
"uid" : "asd"
},
"user_02" : {
"Email" : "all@gmail.com",
"Name" : "all",
"age" : 49,
"owner_uid" : 123,
"uid" : "asdfg"
},
"user_03" : {
"age" : 60,
"email" : "ovenre@gmail.com",
"owner_uid" : 12345,
"uid" : "sdfzsvsvsd"
}
}
}

检查this url 查看数据库的结构。更新:

HTML 代码:

<table class="mdl-data-table mdl-js-data-table ">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Email</th>
<th>Age</th>
<th>uid</th>
</tr>
</thead>
<tbody id="usersData">
</tbody>
</table>

JS代码

var usersRef = firebase.database().ref('Users')
var query = usersRef.orderByChild('owner_uid').equalTo('123');
query.on("child_added", function(snapshot) {

var email = snap.child("Email").val;
var name = snap.child("Name").val;
var uid = snap.child("uid").val;

$("#usersData").append("<tr><td" + email + "</td><td>" + name + "</td><td>" + uid + "</td></tr>");

});

最佳答案

var usersRef = firebase.database().ref('Users')
var query = usersRef.orderByChild('owner_uid').equalTo('YOUR UID HERE');
query.on("child_added", function(snapshot) {
console.log(snapshot.val().uid);
});

关于javascript - Firebase 导入排序数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41544773/

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