在FireStore中订购数据 [英] Ordering Data In FireStore
本文介绍了在FireStore中订购数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每个文档中都有数字数据...我正在使用此代码获取数据
I have numeric data each in every document... I am getting the data using this code
db.collection('Stations').orderBy("station","asc").onSnapshot((querySnapshot) =>{
this.setState({
stations:querySnapshot.docs.map(doc => {
return {
id: doc.id,
station:doc.data().station
}
})
})
});
数据没有正确排列,如下所示:
And the data is not getting arranged properly as seen below:
推荐答案
您正在按使用字典顺序的字符串值进行排序.并且按照字典顺序,"100"
在"2"
之前.
You're ordering by string values, which use lexicographical ordering. And in lexicographical order "100"
comes before "2"
.
要解决您的问题,请创建一个仅包含数值的字段,然后按该字段排序.另外,也可以填充数字,使它们都具有相同的长度,因为"002"
在"100
"之前.
To fix your problem, have a field with only the numerical value, and order by that field. Alternatively pad the numbers so they all have the same length, because "002"
comes before "100
".
另请参阅:
这篇关于在FireStore中订购数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文