firebase - 使用 Firebase 逐个获取元素
问题描述
我想在 Firebase 中获得一个子值,但是我不知道该怎么做。
例子:
/users/{some_user_id_here}/{rank_id_here}
/users/1866/4
例如,当您的 rank id 为 4 时,我需要获取所有用户。
解决方案
以下应该可以解决问题:
var userQuery = firebase.database().ref('users').orderByChild('rank').equalTo(4);
userQuery.once('value', function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var childKey = childSnapshot.key;
var childData = childSnapshot.val();
console.log(childKey);
console.log(childData);
});
});
看看这里的文档:https ://firebase.google.com/docs/database/web/lists-of-data#listen_for_value_events
推荐阅读
- python - Web Crawling - 无法从 HTML 和 XHR 代码中找到数据表
- android - 如何在 PeriodicWorkRequest 中使用 SpeechRecognizer?
- php - 如何使用codeigniter连接来自不同数据库的两个表?
- javascript - 即使条件正确且项目存在,Javascript 地图仍返回未定义
- dask - ValueError:未知字段 ['image']
- javascript - 如何在 JavaScript 中用纬度和经度从地图区域(多边形)偏移特定长度单位?
- powershell - 如何使用 PowerShell Get-ChildItem 检索文件和文件夹?
- javascript - 在编辑器中向 Gutenberg 块包装器添加其他类
- c# - 如何将 .ttf 文件导入到我的 Visual Studio 2017 Web 项目中以用作 CSS 字体系列值?
- c++ - 在 COFF 目标文件中查找代码和数据部分的最佳方法?