2016-11-14 115 views
0

我错过了一些东西或Firebase只是没有排序?Firebase排序不起作用

https://dinosaur-facts.firebaseio.com/dinosaurs.json?orderBy=%22height%22&print=pretty

{  
    "bruhathkayosaurus" : { 
    "appeared" : -70000000, 
    "height" : 25, 
    "length" : 44, 
    "order" : "saurischia", 
    "vanished" : -70000000, 
    "weight" : 135000 
    }, 
    "lambeosaurus" : { 
    "appeared" : -76000000, 
    "height" : 2.1, 
    "length" : 12.5, 
    "order" : "ornithischia", 
    "vanished" : -75000000, 
    "weight" : 5000 
    }, 
    "linhenykus" : { 
    "appeared" : -85000000, 
    "height" : 0.6, 
    "length" : 1, 
    "order" : "theropoda", 
    "vanished" : -75000000, 
    "weight" : 3 
    }, 
    "pterodactyl" : { 
    "appeared" : -150000000, 
    "height" : 0.6, 
    "length" : 0.8, 
    "order" : "pterosauria", 
    "vanished" : -148500000, 
    "weight" : 2 
    }, 
    "stegosaurus" : { 
    "appeared" : -155000000, 
    "height" : 4, 
    "length" : 9, 
    "order" : "ornithischia", 
    "vanished" : -150000000, 
    "weight" : 2500 
    }, 
    "triceratops" : { 
    "appeared" : -68000000, 
    "height" : 3, 
    "length" : 8, 
    "order" : "ornithischia", 
    "vanished" : -66000000, 
    "weight" : 11000 
    } 
} 

的高度不排序,将返回[44,...,0.6,...,3]

回答

4

该请求返回结果作为JSON对象和有是无法表示顺序的,所以orderBy参数不能用于排序结果。

orderBy参数预计会与过滤参数一起使用,如equalTo。请参阅this answer

+2

正确!例如:https://dinosaur-facts.firebaseio.com/dinosaurs.json?orderBy=%22height%22&limitToLast=2&print=pretty – Kato