【问题标题】:Firebase query that returns objects返回对象的 Firebase 查询
【发布时间】:2019-01-07 21:15:01
【问题描述】:

我有以下实时数据库结构

现在我想按所有者查询 aeds,以便查询返回具有匹配所有者 ID 的所有 aeds(带有孩子)。

但不知何故,我无法做到,尽管我觉得这一定很容易。这是我的代码:

var aedRef = dbRef.ref().child("aeds")
var query = aedRef.orderByChild("owner").equalTo(userID);
console.log(query);

我觉得这应该很容易,但不知何故我无法让它发挥作用。我得到的只是这个:

e {repo: e, path: e, Me: e, Le: true}

非常感谢任何帮助

【问题讨论】:

    标签: javascript json firebase firebase-realtime-database


    【解决方案1】:

    query 只是一个文档引用,它不是查询的结果。您需要在其上使用.on.once 以使其返回数据。

    查看Firebase docs 了解有关如何读取和写入数据的更多信息。

    var aedRef = dbRef.ref().child("aeds");
    var query = aedRef.orderByChild("owner").equalTo(userID);
    
    // Get data and keep listening for changes
    query.on('value', function(snapshot) {
      console.log(snapshot.val());
    });
    
    // Only get data once
    query.once('value').then(function(snapshot) {
      console.log(snapshot.val());
    });
    

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 2018-11-11
    • 1970-01-01
    • 1970-01-01
    • 2020-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多