如何仅在Firebase中获取子键 [英] How to only get child keys in Firebase

查看:85
本文介绍了如何仅在Firebase中获取子键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想显示位置的孩子,即信德省和旁遮普省(而不是他们的孩子).有可能吗,如果可以,我该怎么办?

I want to display only children of location i.e Sindh and Punjab (not their children). Is it possible, and if so how can I do it?

推荐答案

来自文档中的数据结构最佳做法:

避免嵌套数据

Avoid nesting data

因为Firebase实时数据库最多可嵌套32个数据 深层次,您可能会觉得这应该是 默认结构.但是,当您在自己的位置获取数据时 数据库,您还将检索其所有子节点.另外,什么时候 您授予某人在数据库节点上的读取或写入访问权限,您 还授予他们访问该节点下所有数据的权限.因此,在 实践中,最好保持数据结构尽可能平坦.

Because the Firebase Realtime Database allows nesting data up to 32 levels deep, you might be tempted to think that this should be the default structure. However, when you fetch data at a location in your database, you also retrieve all of its child nodes. In addition, when you grant someone read or write access at a node in your database, you also grant them access to all data under that node. Therefore, in practice, it's best to keep your data structure as flat as possible.

Firebase的工作方式是:如果您获得一件物品,那么您也将获得它的孩子.如果您不希望这样做,则应该重组数据库.

That is how Firebase works: If you get an item, you get its children as well. If you don't want this, you should restructure the database.

这篇关于如何仅在Firebase中获取子键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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