如何循环访问并获取Firebase中所有嵌套节点的密钥? [英] How do I loop through and get all the keys of the nested nodes in firebase?

查看:98
本文介绍了如何循环访问并获取Firebase中所有嵌套节点的密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取Firebase中嵌套节点的关键字,我不知道如何做到这一点。



例如在这种情况下:

example

我怎么知道2,3,4在1之内?

我正在考虑在firebase中单独列出一个值。但有没有更聪明的方法呢?有没有一种更有效的方法来获取Firebase中所有嵌套节点的键?

解决方案

在Android中



可以访问此快照的所有直接子项。可以在本地for循环中使用:

  for(DataSnapshot child:parent.getChildren()){
//在这里你可以访问child.getKey()
}

在iOS中



$ p $ for(child in snapshot.children){
//在这里您可以访问child.key
}

在网上

  snapshot.forEach(function(childSnapshot){
//这里你可以访问childSnapshot.key
});

你可以把它放在不同的列表或者同一条路径中,重要的是保持记住调用事件时真正检索的数据量。你将如何查询这些信息...这就是为什么在NoSQL中推荐保持扁平节点

I am trying to get the keys of the nested nodes in Firebase and I am not sure how to do this.

For example in this case:

example

How do I know that 2,3,4 exist within 1?

I am thinking of putting a values in a list seperately in firebase. But is there a smarter way of doing this? Is there a more efficient way of getting the keys of all the nested nodes in Firebase?

解决方案

In Android

Gives access to all of the immediate children of this snapshot. Can be used in native for loops:

for (DataSnapshot child : parent.getChildren()) { 
   //Here you can access the child.getKey()
}

In iOS

for (child in snapshot.children) { 
  //Here you can access child.key
}

In Web

snapshot.forEach(function(childSnapshot) {
   //Here you can access  childSnapshot.key
});

You can put it in a different list or in the same path, the important thing is to keep in mind how much data you are really retrieving when calling an event. And how are you going to query that information... that is why it is recommended in NoSQL to keep flat nodes

这篇关于如何循环访问并获取Firebase中所有嵌套节点的密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆