[英]Searchkit Range filter min and max value of data
I'm having problems with making my range filter more dynamic. 我在使范围过滤器更具动态性方面遇到问题。
I have a price filter (RangeFilter), which uses a RangeSliderInput as rangeComponent. 我有一个价格过滤器(RangeFilter),它使用RangeSliderInput作为rangeComponent。 Which looks like this:
看起来像这样:
Filtercode: 过滤代码:
<RangeFilter
title="Prijs"
field="verkoopprijs"
id="verkoopprijs"
min={0}
max={100}
showHistogram = {false}
rangeComponent = {RangeSliderInput}
translations={{"range.submit":"Zoeken"}}
/>
Instead of the hardcoded min 0 and max 100, I would like to get the minimum value and the maximum value of the field verkoopprijs. 而不是硬编码的最小0和最大100,我想获取字段verkoopprijs的最小值和最大值。
A search result looks like this: 搜索结果如下所示:
"hits":{
"total":7271,
"max_score":1.0,
"hits":[
{
"_index":"onixts_prod",
"_id":"9783932346729",
"_score":1.0,
"_source":{
"id":"9783932346729",
"jaar":"2015",
"taal":"Duits",
"hoofdtitel":"Therapie-Handbuch Power Tube, Power QuickZap",
"verkoopprijs":38.95,
}
}
]
}
However. 然而。 I'm not sure how to get the min and max value.
我不确定如何获得最小值和最大值。
According the fact that your search result is in a variable called data
, to get the min and max of the verkoopprijs
field you can: 根据您的搜索结果在名为
data
的变量中的事实,要获取verkoopprijs
字段的最小值和最大值,您可以:
const min = data.hits.hits.reduce((min, curr) => curr.verkoopprijs < min.verkoopprijs ? curr : min, data.hits.hits[0]);
const max = data.hits.hits.reduce((max, curr) => curr.verkoopprijs > max.verkoopprijs ? curr : max, data.hits.hits[0]);
Then, use it as min and max in your component like 然后,将其用作组件中的min和max
<RangeFilter
title="Prijs"
field="verkoopprijs"
id="verkoopprijs"
min={min}
max={max}
showHistogram = {false}
rangeComponent = {RangeSliderInput}
translations={{"range.submit":"Zoeken"}}
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.