【问题标题】:How to apply filter on array of strings in Loopback?如何在 Loopback 中对字符串数组应用过滤器?
【发布时间】:2018-03-14 01:57:38
【问题描述】:

我需要在环回中过滤一个字符串数组。我有以下型号。

{
...
"type": ["string"],
...
}

我使用的过滤器是 {"where":{"type":["filter string"]}}{"type":["filter string"]},但两者都不起作用并返回所有条目。

请帮忙。提前致谢。

【问题讨论】:

    标签: arrays api filter loopback


    【解决方案1】:

    请使用不带方括号的{"where":{"type":"filter string"}}。由于type 被定义为字符串数组,因此此查询将返回带有filter string 作为任意索引元素的条目。

    【讨论】:

    • 状态为 200,但是:响应标头 { "strict-transport-security": "max-age=0; includeSubDomains", "via": "1.1 vegur", "vary": "Origin , Accept-Encoding", "server": "Cowboy", "etag": "W/\"2-l9Fw4VUO7kr8CvBlt4zaMCqXZ0w\"", "x-download-options": "noopen", "x-frame-options": “SAMEORIGIN”、“content-type”:“application/json;charset=utf-8”、“date”:“2017 年 10 月 3 日星期二 17:05:41 GMT”、“x-content-type-options”: “nosniff”、“连接”:“keep-alive”、“access-control-allow-credentials”:“true”、“content-length”:“2”、“x-xss-protection”:“1;模式=块“}
    • 响应有什么问题吗?我无法从您的评论中理解
    • 不,实际上数据在表中。当我单击 try it out 时,它会为我提供表中存在的所有数据,而不管我需要过滤的 type 是什么。我无法找出问题所在,查询是在数据库中设置的,并且我已将 Postgre 用于 DB。
    • Postgre 是一个 SQL 数据库。我的答案对此不起作用,因为它将数组数据存储为字符串。您必须在查询中使用 regexpilikeloopback.io/doc/en/lb2/Where-filter.html#ilike-and-nilike
    • 查询将是:{"where": {"type": {"ilike": "%\"filter string\"%"}}}
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-04
    • 1970-01-01
    • 2021-06-05
    • 2016-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多