我正在使用Evershop Node电子商务平台构建一个应用程序。根据他们的文档,我添加了GraphQL查询产品列表API以获取产品列表。
query GetAllProducts($filters: [FilterInput]) {
products(filters: $filters) {
items {
name
sku
status
image {
alt
thumb
origin
}
price {
regular {
value
text
}
special {
value
text
}
}
weight {
value
unit
}
}
total
currentFilters{
key
value
}
}
}
字符串
在这个查询中,我必须像下面这样将过滤器值传递给变量filters
:
const filters = [
{
key: "limit",
operation: "eq",
value: '10'
},
{
key: "page",
operation: "eq",
value: '1'
},
{
key: "name",
operation: "ilike",
value: '%jeans%'
}
];
型
在我的例子中,你可以看到有一个price字段,它被定义为一个对象。我如何根据price字段按产品列表进行过滤?
1条答案
按热度按时间lp0sw83n1#
要过滤price对象中的特定字段,请使用点表示法直接访问这些字段。
例如,要过滤常规价格大于50的产品,需要按如下方式修改过滤器数组:JavaScript
字符串