【问题标题】:How to filter by nested attributes in JSONAPI?如何按 JSONAPI 中的嵌套属性进行过滤?
【发布时间】:2020-06-04 13:59:43
【问题描述】:

假设我们有以下数据结构

    "data": [
    {
        "type": "node--press",
        "id": "f04eab99-9174-4d00-bbbe-cdf45056660e",
        "attributes": {
            "nid": 130,
            "uuid": "f04eab99-9174-4d00-bbbe-cdf45056660e",
            "title": "TITLE OF NODE",
            "revision_translation_affected": true,
            "path": {
                "alias": "/press/title-of-node",
                "pid": 428,
                "langcode": "es"
            }
...
}

返回的数据符合 JSON API 标准,检索和处理它没有问题,除了我需要能够过滤路径 pid 返回的节点。

如何按 path.pid 过滤我的数据?

我尝试过: - node-press?filter[path][pid]=428 - node-press?filter[path][pid][value]=428

无济于事

【问题讨论】:

  • 您找到解决方案了吗?

标签: json-api


【解决方案1】:

规范的过滤器部分没有很好地定义它,但其他参数(例如include)描述了使用点符号访问嵌套键。您可以尝试?filter[path.pid]=428 并以这种方式解析过滤器。

【讨论】:

    【解决方案2】:
    "field_country": {
                        "data": {
                            "type": "taxonomy_term--country",
                            "id": "818f11ab-dd9d-406b-b1ca-f79491eedd73"
                        }
                    }
    

    以上结构可以通过?filter[field_country.id]=818f11ab-dd9d-406b-b1ca-f79491eedd73过滤

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-01
      • 2016-02-27
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 1970-01-01
      相关资源
      最近更新 更多