如何根据密钥在Firebase控制台中排序节点 [英] How to order the nodes in firebase console based on key

查看:53
本文介绍了如何根据密钥在Firebase控制台中排序节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户节点,密钥为1到1400,但顺序不正确. 热门在控制台中按顺序查看.我在另一个节点上也有类似的经历.但后来自动订购

I have a node for users with key 1 to 1400 but it's not in order. Hot to view this in order in the console. I had a similar experience with another node. But it later got ordered automatically

推荐答案

不幸的是,您无法在Firebase数据库控制台中更改节点的顺序.默认情况下,所有节点均按键排序.要记住的一件事是Firebase键是Strings.当字符串排序时,按lexicographically排序.

Unfortunately, you cannot change the order of the nodes in the Firebase Database Console. By default, all the nodes are ordered by key. One thing to remember is that Firebase keys are Strings. And when strings are order, are ordered lexicographically.

所以对于数字,这是正常的顺序:

So for numbers, this is the normal order:

  • 1308
  • 1309
  • 1310
  • 1311

但是对于字符串,这是正常的顺序:

But for strings, this is the normal order:

  • "1308"
  • "1309"
  • "131"
  • "1310"

在Firebase中,据我所知,在大多数其他数据库中也没有允许您更改此行为的运算符.相反,您将必须修改数据以获得所需的行为.因此,按字典顺序排序时,请按照您需要的顺序存储值.对于数字,您可以通过用零填充数字来实现:

There is no operator in Firebase and as far as i know nor in most other databases that allow you to change this behavior. Instead, you will have to modify the data to get the behavior you want. So, store values that are in the order you need them when sorted lexicographically. For numbers you can accomplish that by padding them with zeroes:

  • "0131"//之前加零
  • "0132"//之前加零
  • ......
  • "1308"
  • "1309"
  • "1310"
  • "1311"

这篇关于如何根据密钥在Firebase控制台中排序节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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