【发布时间】:2022-01-03 06:44:20
【问题描述】:
示例 json 数据是这样的:
{
"variations": [
{
"variation_id": 391,
"name": "Fruit Shake - Chocolate, S",
"price": 10,
"attribute": [
{
"attribute_key": "pa_flavor",
"name": "Flavor",
"option": "Chocolate"
},
{
"attribute_key": "pa_size",
"name": "Size",
"option": "S"
}
]
},
{
"variation_id": 385,
"name": "Fruit Shake - Banana, L",
"price": 18,
"attribute": [
{
"attribute_key": "pa_flavor",
"name": "Flavor",
"option": "Banana"
},
{
"attribute_key": "pa_size",
"name": "Size",
"option": "L"
}
]
},
{
"variation_id": 386,
"name": "Fruit Shake - Banana, M",
"price": 15,
"attribute": [
{
"attribute_key": "pa_flavor",
"name": "Flavor",
"option": "Banana"
},
{
"attribute_key": "pa_size",
"name": "Size",
"option": "M"
}
]
}
]
}
我的问题是,获取 2 个或更多属性与字符串数组匹配的变量 ID。
例如,chonedProduct = ["Banana", "L"]
我尝试了过滤和包含,但无法匹配来自 selectedProduct 的其他项目。
如果我添加了下一个条件,则返回 nil
【问题讨论】:
-
将代码添加为文本而不是图像,并包含您声明的数据结构