简体   繁体   English

Searchkit范围过滤器数据的最小值和最大值

[英]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.

相关问题 用最小最大范围反应年份选择器 - React year picker with min max range 如何区分 slider 范围的值,如何使用它们在屏幕上将最小值和最大值显示为 output? - How can I separate values of range slider and how can I use them for showing min and max value as output on screen? 为什么最小和最大范围方法不返回有效的 output - Why min and max range method does not return valid output 使用reactJS创建价格范围字段(最小和最大) - Create price range fields (min and max) using reactJS 如何以水平方式显示最小值和最大值? - how to show min and max value in horizontal manner? 在范围输入中,当 min 和 max 相等时,幻灯片应该只是一个点? - in range input, when min and max are equal, the slide should just be a dot? searchkit:RefinementListFilter无法访问json中的某些数据 - searchkit: RefinementListFilter can't access certain data in json 如何在 React 中为增量和减量方法设置最大值和最小值 - How to set max and min value for increment and decrement methods inside React 最小值和最大值 Reactstrap 输入类型日期(日历) - Min and Max value Reactstrap Input Type Date (Calendar) 如何在 redux-form 中为 Field 设置“min”和“max”值 - how to set “min” and “max” value for Field in redux-form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM