【发布时间】:2016-10-16 13:21:26
【问题描述】:
我从 Firebase 数据库中的查询开始,并且会喜欢更多的见解。
此查询适用于从 firebase 数据库中检索单个项目。我的理解内联。
var ref = DatabaseRef; // root of my fbase db
var codeRef = ref.child('codes'); // at root/codes/ now
codeRef
.child($stateParams.codeId) // a param comes in
// grab value one-time
// https://www.firebase.com/docs/web/guide/retrieving-data.html#section-reading-once
.once('value', function(snap) {
console.log(snap.val());
})
以上工作。但是下面没有,为什么?我的理解内联。
// same ref from above
codeRef
// traverse the /codes/ url, and find all items that match
// the specified param
.equalTo($stateParams.codeId)
.once('value', function(snap) {
console.log(snap.val()); // returns `null`
})
相反,我希望显示与该 ID 匹配的所有项目。在这种情况下,id 是唯一的,因此,我希望得到一个单品。但是,会返回 null。
来自docs:
equalTo() 方法允许我们根据精确匹配进行过滤。与其他范围查询一样,它将针对每个匹配的子节点触发。
所以,也许我看错了整个 Firebase 查询。会喜欢开悟。
【问题讨论】:
标签: firebase angularfire firebase-realtime-database