为什么 firebase 查询看起来不像列表? [英] Why doesn't the firebase query look like list?
问题描述
我正在根据日期查询 firebase.我找到了我的查询,但它看起来不像 firebase.这个顺序对我很重要.另一个图片链接:firebase
I'm querying firebase based on the dates. I find my query, but it doesn't look like firebase. The order of this is important to me. another picture link : firebase
-LP6nkhewJCIGplnE6L4
adSoyad:
"RUKIYE POLAT"
tarih:
"18/10/2018,18:33:02"
-LP7EBqo6pabsweqH-4G
adSoyad:
"RUKIYE POLAT"
tarih:
"18/10/2018,20:32:56"
-LPBblB72HizL1LaJDIp
adSoyad:
"RUKIYE POLAT"
tarih:
"19/10/2018,16:58:45"
-LPCNo2DoDkArJJUQMCp
adSoyad:
"RUKIYE POLAT"
tarih:
"19/10/2018,20:33:01"
-LPF-MEziEXaoaNezNHQ
adSoyad:
"RUKIYE POLAT"
tarih:
"20/10/2018,8:45:03"
-LPGfoeIVNGq1MRmOEbY
adSoyad:
"RUKIYE POLAT"
tarih:
"20/10/2018,16:34:34"
-LPGfpCRniADm6sgGWyy
adSoyad:
"RUKIYE POLAT"
tarih:
"20/10/2018,16:34:34"
-LPK8Puua1kLv5eV7NOF
adSoyad:
"RUKIYE POLAT"
tarih:
"21/10/2018,8:42:44"
-LPLqoKyV_YiaMqKozxb
adSoyad:
"RUKIYE POLAT"
tarih:
"21/10/2018,16:40:42"
-LPLqosW54-5q8hUfNoK
adSoyad:
"RUKIYE POLAT"
tarih:
"21/10/2018,16:40:43"
示例,在 Firebase 中Date: 20/10/2018,8: 32
Date: 20/10/2018,16: 39
sample, in Firebase
Date: 20/10 / 2018,8: 32
there is another child under Date: 20/10 / 2018,16: 39
我也想按这个顺序来.根据数据库中的时间,即按照firebase中的列表顺序.但首先,即将到来
I also want to come like in this order. According to the time from the database ie in the order of the list as in the firebase.But Firstly,is coming
Date: 20/10 / 2018,16: 39
Date: 20/10 / 2018,8: 32
但我想如上所列首先日期:20/10/2018,8:32日期:20/10/2018,16:39
另一个图片链接:https://i.hizliresim.com/j691AL.jpg申请
But I want to as listed above
first
Date: 20/10 / 2018,8: 32
Date: 20/10 / 2018,16: 39
another picture link :https://i.hizliresim.com/j691AL.jpg
application
数据库中有很多数据,所以我无法修复它.
There are a lot of data in the database, so I can't fix it.
DatabaseReference dbGelenler = db.getReference(kimlik+"/"+cekilensifre+"/"+cekilenisim);
Query query = dbGelenler.orderByChild("tarih").startAt(birincitarih).endAt(birincitarih + "uf8ff");
query.addListenerForSingleValueEvent(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
List<String> isimler = new ArrayList<String>();
for (DataSnapshot anahtar : dataSnapshot.getChildren()) {
String isim = anahtar.getValue(ornekogrencigetir.class).getAdSoyad();
String tarih = anahtar.getValue(ornekogrencigetir.class).getTarih();
HashMap<String, String> user = new HashMap<>();
if (isimler.indexOf(isim) == -1) {
user.put("hashdurum", "Giriş");
String[] seperated;
seperated = tarih.split(",");
user.put("hashtarih", seperated[0]);
user.put("hashsaat", seperated[1]);
} else {
user.put("hashdurum", "Çıkış");
String[] seperated1;
seperated1 = tarih.split(",");
user.put("hashtarih", seperated1[0]);
user.put("hashsaat", seperated1[1]);
}
isimler.add(isim);
veriler.add(user);
为什么查询不采用顺序方式?我该如何解决这个问题?
Why doesn't the query take a sequential manner? How can I fix this?
错误解决:
查询信息按时间排序.有时在我的数据库前面不包含0.这些是从 12 点之后到早上 10 点的时间.例如,上午 9 点.因此,在比较firebase时钟时,请参考下一个.情况示例9:12:15到15:24:54他这里比较的情况是91和15,所以他先拿15:24:54,然后拿9:12:15.
推荐答案
您将日期/时间以字符串值存储在数据库中,格式为 dd/MM/yyyy hh:mm:ss
.Firebase 中的字符串是按字典顺序排列的,不幸的是,在您使用的日期格式中,值的字典顺序和时间顺序是不同的.
You store the date/time in your database in a string value, in the format dd/MM/yyyy hh:mm:ss
. Strings in Firebase are lexicographically ordered, and unfortunately in the date format you use, the lexicographical order and the chronological order of the values are different.
解决方案是以允许按您想要的方式对其进行排序的格式存储日期/时间值.两种最常见的方法是将它们存储为时间戳(一个数值,表示自特定日期以来的毫秒数),或以可排序的字符串格式(通常为 2018-10-20T16:34:34
2018-10-20T16:34:34代码>).
The solution is to store the date/time value in a format that does allow it to be sorted in the way you want. The two most common ways are to store them as a timestamp (a numeric value that is the number of milliseconds since a specific date), or in a sortable string format (typically 2018-10-20T16:34:34
).
有关这方面的更多信息,请参阅:
For more on this, see:
这篇关于为什么 firebase 查询看起来不像列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!