问题描述
我试图找出如何立足火力地堡及其子子节点来过滤产品。
我的设置如下:
产品/
产品1
/作者:12345
/标题:真棒
/描述:真棒多
产品2
/作者:67890
/标题:真棒
/描述:真棒多
我如何查询火力地堡,这样我仅检索其所持有的产品,子($的productId).child(作者)
等于 12345
?
我尝试以下,但是这显然是行不通的。我需要一种方法来在subchild筛选:
REF VAR =新火力地堡(FBURL);//附加异步回调自己的岗位参考读取数据
ref.child(产品)。孩子('$的productId')。子女(作家)。equalTo(12345)。在(价值,功能(快照){
的console.log(snapshot.val());
},功能(errorObject){
的console.log(读失败:+ errorObject code);
});
只需使用 orderByChild()
:
ref.child(产品)。orderByChild('作家')。equalTo(12345)...
这将责令下产品每个子节点
由它的作者
属性,然后只返回具有的那些值 12345
。
请参阅的。
I am trying to figure out how to filter products based on their sub child nodes in Firebase.
My setup is as follows:
products/
product1
/author: 12345
/title: "Awesome"
/description: "more awesome"
product2
/author: 67890
/title: "Awesome"
/description: "more awesome"
How can I query Firebase such that I retrieve only the products for which it holds that child($productId).child(author)
equals 12345
?
I tried the following, but that obviously does not work. I need a way to filter on the subchild:
var ref = new Firebase(FBURL);
// Attach an asynchronous callback to read the data at our posts reference
ref.child("products").child('$productId').child('author').equalTo(12345).on("value", function(snapshot) {
console.log(snapshot.val());
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
Simply use orderByChild()
:
ref.child("products").orderByChild('author').equalTo(12345)...
This will order every child node under products
by its author
property and then return only the ones that have a value of 12345
.
See Firebase's documentation on queries.
这篇关于基于子子在火力地堡过滤制品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!