<分区>
如何在从 Firebase 检索数据时知道这是否是最后一个 child ?
<分区>
如何在从 Firebase 检索数据时知道这是否是最后一个 child ?
最佳答案
根据 Firebase documentation :
public DatabaseReference getParent()
A DatabaseReference to the parent location, or null if this instance references the root locationpublic DatabaseReference getRoot()
A reference to the root location of this Firebase Database
因此,您可以在 DatabaseReference 对象上使用 getRoot() 以始终转到根目录,或者使用 getParent() 直到得到 null。
您应该以扁平化结构构建数据,这样您就不会对数据的结束位置 ( documentation ) 感到困惑:
Avoid nesting data
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.
关于android - 检查 Firebase android 中的最后一个 child 是否,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40338242/