按升序/降序对Firebase数据进行排序 [英] Sort Firebase data in ascending/Descending Order

查看:89
本文介绍了按升序/降序对Firebase数据进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理库存管理项目,我的客户希望按升序和降序销售股票.

I'm Working with stock management project and my client want sales of stock in ascending and descending order.

我的库存结构如下

我想根据产品的销售情况对数据进行排序.

I want to sort the data as per the sales of the product.

注意:此数据库中有成千上万的产品,因此下载数据然后对其进行排序不是一个好主意.我相信这会减慢该过程.

NOTE: There are thousands of products in this database, so downloading and then sorting the data isn't good idea. I believe this will slow down the process.

推荐答案

您可以使用orderByChild函数从firebase中以升序获取已排序的数据.您将需要在table上创建索引. 请参阅Firebase分类数据部分 https://firebase.google.com/docs/database/android/数据列表

You can get sorred data in ascending order from firebase using orderByChild function.you will need to create indexes on table . Refer firebase sorting data section https://firebase.google.com/docs/database/android/lists-of-data

//降序:

已经对列表进行了排序,请在客户端执行此任务.使用集合内置函数来反转列表Collections.reverse(inputList)

Do this task at client side as you already have sorted list. Use collections inbuilt function to reverse the list Collections.reverse(inputList)

希望这对您有所帮助:)

Hope this helps you :)

这篇关于按升序/降序对Firebase数据进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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