0
我目前使用Firebase作为数据库,并试图使用orderbypriority对我的Firebase条目进行排序。但是我有一个orderbypriority的问题。当我在firebase引用上使用orderbypriority查询我的数据库时,它不会按照每个元素的优先级顺序返回数据。这里是我的代码,我使用:Firebase orderby优先级不工作
Firebase answersRef = new Firebase("/Questions/ModeratorQuestions/General/" + question.getKey() + "/Answers");
answersRef.orderByPriority().addListenerForSingleValueEvent(new ValueEventListener(
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
System.out.println(dataSnapshot);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
这里是我的数据库是如何内火力
-Questions
-ModeratorQuestions
-General
-QuestionIdNumber
-Answers
-Answer 1 (With priority of 0)
-Answer 2 (With priority of 1)
-Answer 3 (With priority of 2)
快照设置可以发现here。
这里是我从dataSnapshot得到的输出,当我尝试查询我的代码中上面指定的url时(我从url中取出项目名称)。
{ key = Answers, value = {Douglas_Comer={.priority=0.0, .value=0}, Sophie_Dee={.priority=1.0, .value=0}} }
{ key = Answers, value = {Yes={.priority=0.0, .value=0}, No={.priority=1.0, .value=0}} }
{ key = Answers, value = {Go_on_a_shopping_spree_at_the_mall={.priority=1.0, .value=0}, Donate_it_to_charity={.priority=3.0, .value=0}, Stocks={.priority=4.0, .value=0}, Go_to_Walmart_I'll_figure_out_the_rest_when_I_get_there={.priority=2.0, .value=0}, DANCE={.priority=0.0, .value=0}} }
{ key = Answers, value = {Yes={.priority=0.0, .value=0}, Love_is_Dead={.priority=2.0, .value=0}, No={.priority=1.0, .value=0}} }
{ key = Answers, value = {three_landmines={.priority=1.0, .value=0}, 1,000_non-venomous_snakes={.priority=0.0, .value=0}} }
{ key = Answers, value = {have_free,_coach-seating,_air_travel_once_a_month={.priority=1.0, .value=0}, own_a_yacht={.priority=0.0, .value=0}} }
{ key = Answers, value = {Valentine's={.priority=3.0, .value=0}, Thanksgiving={.priority=2.0, .value=0}, Other={.priority=4.0, .value=0}, Halloween={.priority=1.0, .value=0}, Christmas={.priority=0.0, .value=0}} }
{ key = Answers, value = {Bread={.priority=0.0, .value=0}, Tortillas={.priority=3.0, .value=0}, Pasta={.priority=2.0, .value=0}, Rice={.priority=1.0, .value=0}} }
{ key = Answers, value = {fight_your_crush={.priority=0.0, .value=0}, fight_a_bear_cub={.priority=1.0, .value=0}} }
{ key = Answers, value = {Happy_relationship={.priority=0.0, .value=0}, Eligible_Bachelor={.priority=1.0, .value=0}, NULL_POINTER_EXCEPTION={.priority=2.0, .value=0}, Focused_on_beautiful_Science={.priority=4.0, .value=0}, I_have_no_idea_what_I'm_doing={.priority=3.0, .value=0}} }
{ key = Answers, value = {Apples={.priority=0.0, .value=0}, Bananas={.priority=1.0, .value=0}, Oranges={.priority=2.0, .value=0}} }
正如你所看到的,他们中的大多数不是按他们的优先顺序排列的。我不明白为什么。如果有人可以帮我解决我做错的事情,那将是值得赞赏的。如果您需要更多信息,我也可以回答问题。
你可以复制/粘贴您的Firebase数据结构简要快照到问题中? – Jay
@Jay No我需要至少10个声望才能发布图片,我没有,但是可以在http://imgur.com/y5ydfoz找到图片 – Michael41000
您不应该发布图片,而是发布实际文字。您可以通过按导出按钮轻松地从Firebase仪表板获取该信息。 –