【发布时间】:2020-03-10 19:28:36
【问题描述】:
我正在尝试使用 firebase firestore 构建一个电子商务应用程序,但我一直停留在根据用户输入对产品进行过滤和排序。我可以应用所有过滤器和排序,但我想对用户输入进行过滤器,我不能将 where 子句留空
所以我想在没有 so if 的情况下根据用户输入生成一个 fire base 查询,或者将 where 子句留空,这样它就不会影响查询
如何动态生成查询
.collection('allProducts')
.where('published', '==', true)
.where('category', 'array-contains-any', keyword)
.where('color', '==', colorSelected)
.orderBy('price')
.where('price', '>', priceRange[0])
.where('price', '<', priceRange[1])
.orderBy('createdAt', 'desc');```
【问题讨论】:
-
“将 where 子句留空”是什么意思?
-
例如,用户不想按颜色过滤,所以我必须将 colorSelected 留空,这是我无法做到的,或者删除 where 子句本身。所以我正在寻找一种在用户选择的输入上动态生成此查询的方法
标签: reactjs firebase google-cloud-firestore