firebase - 如何在分页flutter firestore之前过滤数据
问题描述
我正在申请租车。我正在通过分页(限制 3)过滤它们以降低价格,但在某些情况下,公司可以提供折扣。发生这种情况时,我的数据库过滤变得无效。例如,数据库中有 4 辆汽车(40 美元、50 美元、60 美元、70 美元)。当我使用此代码过滤数据时:
var availableCars = await _firestore
.collection('carMini')
.where('locations', arrayContains: order.address)
.orderBy('carPrice', descending: false)
.limit(3)
.get();
即使第 4 辆车的折扣价低于其他车,这个价格也会出现较晚,因为数据带有分页。有什么办法可以预先设置吗?
解决方案
Firestore 查询无法过滤此类计算值。使单个查询正常工作的唯一方法是将有效/折扣价格存储在单独的字段中并对其进行排序/过滤。
var availableCars = await _firestore
.collection('carMini')
.where('locations', arrayContains: order.address)
.orderBy('discountedCarPrice')
.limit(3)
.get();
推荐阅读
- azure-devops - Azure Pipeline DB Build 随机失败并出现 EsentVersionStoreOutOfMemoryException:版本存储内存不足
- clojure - 在clojure中对序列中的元素进行排名
- docker - 读取 unix @->/var/run/docker.sock:读取:连接由对等方重置
- r - 具有正态分布和对数链接的 glm 模型
- sccm - 使用 32 位启动器运行 .cmd?
- azure-devops - 尝试将构建发布到 Nuget.org
- ios - CallKit:iOS 集成 - CXProviderConfiguration 不起作用
- excel - 如何循环多个文本框以设置透明度
- java - 搜索过滤器需要在 Active Directory 中查找具有 networkID 的用户
- html - 如何构建对角英雄部分?