Javascript 如何获取匹配子级的firebase快照?

Javascript 如何获取匹配子级的firebase快照?,javascript,firebase,search,firebase-realtime-database,Javascript,Firebase,Search,Firebase Realtime Database,我有这种格式的firebase数据结构 当用户在搜索字段中输入5133-01-329-5971时,我希望能够获取的快照 5133-01-329-5971-OkqcPp3xJwfgmNinwGsKZmAa8xt1-1508951718305 5133-01-329-5971-OkqcPp3xJwfgmNinwGsKZmAa8xt1-1508966816945 因为它们包含用户输入的匹配项 此代码将为我提供节点中的所有子节点 var itemdetailref = Cataloguedatab

我有这种格式的firebase数据结构

当用户在搜索字段中输入5133-01-329-5971时,我希望能够获取的快照

5133-01-329-5971-OkqcPp3xJwfgmNinwGsKZmAa8xt1-1508951718305

5133-01-329-5971-OkqcPp3xJwfgmNinwGsKZmAa8xt1-1508966816945

因为它们包含用户输入的匹配项

此代码将为我提供节点中的所有子节点

  var itemdetailref = Cataloguedatabase.ref('/Listings/');

  return itemdetailref.once('value').then(function(snapshot){

  })

如何获取与5133-01-329-5971匹配的所有子项的快照?

如果您只需要寻找一个特殊的子项,可以在ref变量中输入此字符串。类似如下:

let uid = "5133-01-329-5971";
let child = "-OkqcPp3xJwfgmNinwGsKZmAa8xt1-1508966816945";
var itemdetailref = Cataloguedatabase.ref('/Listings/'+uid+child);

return itemdetailref.once('value').then(function(snapshot){

})
但是如果你像在你的例子中那样搜索多个孩子,你必须得到每个孩子,然后只需要这些孩子包括你的用户ID。比如:

var itemdetailref = Cataloguedatabase.ref('/Listings/'+uid+child);

return itemdetailref.once('value').then(function(snapshot){
        snapshot.forEach(childSnapshot => {
            let key = childSnapshot.key;
            let uid = "5133-01-329-5971";
            //use ES6 includes function
            if(key.includes(uid)){
                myFunction(childSnapshot.val());
            }
        });
})