orderByChild()如果数值相同,如何根据第二个变量排序?

huangapple go评论70阅读模式
英文:

orderByChild() if same value, how to order by second variable?

问题

我按年龄排序的列表。当年龄相同时,我希望按姓名字母顺序排序。

在这种情况下,Adam 应该在上方,Ramsay 应该在下方。

我不知道如何使用 orderByChild() 处理第二个变量。

val database = FirebaseDatabase.getInstance().getReference("Classmate").child("student").orderByChild("age")

// orderByChild("name") // 用于第二排序
英文:

I work with a list sorted by age. When there are same age, I want it to be sorted by name alphabetically.

orderByChild()如果数值相同,如何根据第二个变量排序?

In this case, Adam should be above and Ramsay should be below.

I don't know how to work with orderByChild() for the second variable.

val database = FirebaseDatabase.getInstance().getReference("Classmate").child("student").orderByChild("age")

// orderByChild("name") // for second order

答案1

得分: 3

当仅使用.orderBy("attribute")时,您可以链接多个以在最后一个顺序内对结果进行排序。例如:.orderBy("age").orderBy("name")

val database = FirebaseDatabase.getInstance().getReference("Classmate").child("student").orderByChild("age").orderBy("name")

我没有在orderByChild()中使用过它,但我猜它应该以相同的方式工作。

英文:

When using just .orderBy("atribute") you can chain multiple ones to order the results inside the last order. For example: .orderBy("age").orderBy("name")

val database = FirebaseDatabase.getInstance().getReference("Classmate").child("student").orderByChild("age").orderBy("name")

I haven't used it with orderByChild() but i guess it would work the same way.

huangapple
  • 本文由 发表于 2020年10月3日 00:52:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/64175419.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定