Commercetools-使用查询谓词对集合属性进行过滤

时间:2019-02-18 16:45:09

标签: predicate commercetools sphere.io

我想获得所有在其祖先之间具有特定“ id”的祖先类别的项。

这是 GET /categories返回的类别之一的JSON:

{
        "id": "4627f3b0-fe52-4cc6-b03e-3fd72e701342",
        "version": 1,
        "lastMessageSequenceNumber": 1,
        "createdAt": "2019-02-18T13:48:51.677Z",
        "lastModifiedAt": "2019-02-18T13:48:51.677Z",
        "lastModifiedBy": {
            "clientId": "_anonymous"
        },
        "createdBy": {
            "clientId": "_anonymous"
        },
        "key": "snowboard-gloves",
        "name": {
            "en": "Snowboard Gloves"
        },
        "slug": {
            "en": "snowboard-gloves"
        },
        "description": {
            "en": "Gloves specifically designed for snowboarding"
        },
        "ancestors": [
            {
                "typeId": "category",
                "id": "b27086d2-33f2-43c3-aad1-4c01b2b9a886"
            }
        ],
        "parent": {
            "typeId": "category",
            "id": "b27086d2-33f2-43c3-aad1-4c01b2b9a886"
        },
        "orderHint": "0.000016",
        "metaTitle": {
            "en": "Snowboard Gloves"
        },
        "metaDescription": {
            "en": "Gloves specifically designed for snowboarding"
        },
        "assets": []
    }

我想用/categories上的 where 子句调用ancestors[x].id = "b27086d2-33f2-43c3-aad1-4c01b2b9a886" API,但是从documentation开始,我不知道该怎么写查询谓词。

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

查询谓词遵循json响应的结构。嵌套字段使用()括号进行访问。

尝试一下

ancestors(id = "idb27086d2-33f2-43c3-aad1-4c01b2b9a886")

问候 布莱恩