Querying by range in firebase

前端 未结 1 1535
没有蜡笔的小新
没有蜡笔的小新 2020-12-22 05:16

I have a range slider for prices of food , and based on the min and max of the slider , I want to display the foods which are in this range.

Slider code



        
相关标签:
1条回答
  • 2020-12-22 05:44

    You're storing numeric values as strings in the database. Firebase sorts strings lexicographically. In lexicographical order of you have number from 1 to 12, they are sorted as "1", "10", "11", "12", "2", "3", "4", "5", "6", "7", "8", "9". So the range from "1" to "10" is precisely those two "numbers".

    To solve this problem, store your numeric values as actual numbers in the database.

    Also see:

    • firebase orderByChild returns weird order for only one child
    • Firebase query by date string
    • firebase database order by value working wrong
    • Firebase query ordering not working properly
    • other questions mentioning lexicographical sorting on Firebase
    0 讨论(0)
提交回复
热议问题