在火力地堡多个子属性过滤器产品

编程入门 行业动态 更新时间:2024-10-19 18:32:15
本文介绍了在火力地堡多个子属性过滤器产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

最近,我问怎么根据他们的子属性(见过滤产品:Filter根据火力地堡子子)的产品。

作为一个回顾我的结构如下:

产品/     产品1        /作者:12345        /标题:真棒        /类别:CATA        /描述:真棒多     产品2        /作者:67890        /标题:其他        /类别:CATB        /描述:otherawesome     产品3        /作者:12345        /标题:比利        /类别:CATB        /描述:otherawesome

和筛选出与作者所有产品 12345 我们可以简单地使用:

ref.child(产品)。orderByChild('作家')。equalTo(12345)...

但是,做什么时,我有多个AND陈述或者多个或声明?

所以,如果我想筛选出:

  • 所有产品均拥有作者 12345 和类别 CATA (返回产品1 )

  • 所有产品均拥有作者 12345 或作者67890(返回产品1 和产品3 )

有关第一部分,我想:

ref.child(\"products\").orderByChild('author').equalTo(12345).orderByChild('category').equalTo('catA')...

但没有工作(会抛出错误不能将多个排序依据通话)

另请参阅: www.firebase/docs/web /guide/retrieving-data.html#section-queries

解决方案

从我读过here,要做到这一点的方法是执行第一个查询(preferably一个将返回结果最少的),那么在JavaScript中的其他字段进行筛选。另一种方式来做到这一点,我建议这个,如果你经常执行该查询,是创建查询像一个复合索引;在上面的链接,答案由弗兰克面包车Puffelen给出了这样一个例子。

产品/     产品1        /作者:12345        /标题:真棒        /类别:CATA        /描述:真棒多        / author_category:12345_catA     产品2        /作者:67890        /标题:其他        /类别:CATB        /描述:otherawesome        / author_category:67890_catB     产品3        /作者:12345        /标题:比利        /类别:CATB        /描述:otherawesome        / author_category:12345_catB

至于'OR',我已经看了好一阵子,发现无能为力了。我建议两个单独的查询。

I recently asked how to filter products based on their child property (see: Filter products based on the sub child in Firebase).

As a recap my structure looks as follows:

products/ product1 /author: 12345 /title: "Awesome" /category: "catA" /description: "more awesome" product2 /author: 67890 /title: "Other" /category: "catB" /description: "otherawesome" product3 /author: 12345 /title: "Billy" /category: "catB" /description: "otherawesome"

And to filter out all products with author 12345 we can simply use:

ref.child("products").orderByChild('author').equalTo(12345)...

However, what to do when I have multiple AND statements or multiple OR statements?

So what if I want to filter out:

  • all products with author 12345 AND category catA (returns product1)

  • all products with author 12345 OR author 67890 (returns product1 and product3)

For the first part, I tried:

ref.child("products").orderByChild('author').equalTo(12345).orderByChild('category').equalTo('catA')...

but that did not work (throws error You can't combine multiple orderBy calls)

See also: www.firebase/docs/web/guide/retrieving-data.html#section-queries

解决方案

From what I've read here, the way to do this is to perform the first query (preferably the one that will return the fewest results), then filter by the other field in javascript. Another way to do this, and I'd recommend this if you are performing this query often, is create a compound index for the query like; the answer by Frank van Puffelen in the link above gives an example of this.

products/ product1 /author: 12345 /title: "Awesome" /category: "catA" /description: "more awesome" /author_category: "12345_catA" product2 /author: 67890 /title: "Other" /category: "catB" /description: "otherawesome" /author_category: "67890_catB" product3 /author: 12345 /title: "Billy" /category: "catB" /description: "otherawesome" /author_category: "12345_catB"

As for the 'OR', I've looked for quite a while and found nothing to help you. I'd suggest two separate queries.

更多推荐

在火力地堡多个子属性过滤器产品

本文发布于:2023-11-22 13:46:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1617664.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:地堡   多个   火力   过滤器   属性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!