【问题标题】:Filter 'or' and 'and' together in Loopback 4在 Loopback 4 中一起过滤 'or' 和 'and'
【发布时间】:2020-04-17 08:37:28
【问题描述】:

我正在使用环回 4 并尝试通过 rest api 一起使用过滤器 [and] 和 [or]。我有一张这样的桌子

我想要的是show only items which has cond1 = 0 and cond2 = 0 and (cond3 = 1 or cond3 = 2 or cond3 = 3)

json 会是这样的

{
  "and": [
      {
        "cond1": 0
      },
      {
        "cond2": 0
      },
      {
        "or": [
          {
            "cond3":1
          },
          {
            "cond3":2
          },
          {
            "cond3":3
          }
        ]
     }
  ]
}

这是我的rest api过滤器

filter[where][and][0][cond1]=0&filter[where][and][1][cond2]=0&filter[where][and][2][or][0][cond3]=1&&filter[where][and][2][or][1][cond3]=2&&filter[where][and][2][or][2][cond3]=3

我发现了类似的帖子here,我所做的与Ebrahim Pasbani 的答案看起来相似。

但是没有得到这个结果

我要了这个

这意味着[and][2][or][0] 语法被环回理解为[neq]。我试着四处打听,但看起来其他人也和我有同样的问题,最终没有得到解决。我将不胜感激任何答案,并可能有一些解释。

感谢之前

【问题讨论】:

    标签: rest filter strongloop loopback


    【解决方案1】:

    在环回电报组上找到答案。

    显然,您可以在 rest api 中编写 json 字符串(肯定会使用符号翻译)。所以答案是:

    filter={%22%where%22:{%22and%22:[{%22or%22:[{%22cond3%22:1}{%22cond3%22:2},{%22cond3%22:3}]}],%22cond1%22:0,%22cond2%22:0}}
    

    注意:%22 => " 在 url 字符串中。

    然后瞧…… 结果完全符合我的预期。希望这可以为遇到相同问题的任何人提供答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多