orderByChild()如果值相同,如何按第二个变量排序? [英] orderByChild() if same value, how to order by second variable?

查看:134
本文介绍了orderByChild()如果值相同,如何按第二个变量排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用按年龄排序的列表.如果年龄相同,我希望按名字的字母顺序对其进行排序.

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

在这种情况下,亚当应该在上方,拉姆齐应该在下方.

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

我不知道如何对第二个变量使用orderByChild().

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

推荐答案

仅使用.orderBy("atribute")时,您可以将多个链接在一起以将结果排序到最后一个顺序内.例如:.orderBy("age").orderBy("name")

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")

我没有将它与orderByChild()一起使用,但我想它会以相同的方式工作.

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

这篇关于orderByChild()如果值相同,如何按第二个变量排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆