第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

匹配數(shù)組中的價(jià)格過濾器值并獲取兩個(gè)給定價(jià)格滑塊值之間的價(jià)格值

匹配數(shù)組中的價(jià)格過濾器值并獲取兩個(gè)給定價(jià)格滑塊值之間的價(jià)格值

慕勒3428872 2023-03-03 10:22:38
我有兩個(gè)數(shù)組,一個(gè)數(shù)組是價(jià)格滑塊的值,其中它們是兩個(gè)值,一個(gè)是起始值,另一個(gè)是滑塊的結(jié)束值,我想檢查滑塊開始值和結(jié)束值之間的價(jià)格和值,請(qǐng)查看截圖作為起始值和結(jié)束值的滑塊代碼$(function() {  $( "#slider-range" ).slider({    range: true,    min: 0,    max: 200,    values: [ 1, 50 ],    slide: function( event, ui ) {      $( "#amount" ).text( "$" + ui.values[ 0 ] + "-$" + ui.values[ 1 ] );      collection.filterPrice(event, ui, getPriceTags());    }  });  $( "#amount" ).text( "$1" + "-$" + $( "#slider-range" ).slider( "values", 1 ) );});出滑塊我想要的結(jié)果是if slider value is from 10 to 50 so this checks the into the arrayif any of the value is in between these 10 to 50 so it gives the result 20 50orif slider value is 10 to 60 so the results should be 20 50 and 50 to 100
查看完整描述

3 回答

?
拉丁的傳說

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個(gè)贊

(我希望這終于到了重點(diǎn)......)


此代碼返回范圍與滑塊選擇的價(jià)格范圍重疊(完全或部分)的所有價(jià)格段。


/*

 * NOTES: price segments should not overlap

 */


const priceSegments = ['20-50', '51-100']; // originally was ['20-50', '50-100'] see note

const sliderRange = [1, 50];

const pricesList = [{

    value: 30.5,

    count: 2

  },

  {

    value: 27.7,

    count: 1

  },

  {

    value: 50.0,

    count: 2

  },

  {

    value: 55.5,

    count: 2

  }

];


// if you want an array of strings (e.g. ["20-50", "51-100"])

const priceSegmentsMatchingRange_arrayOfStrings = priceSegments.filter(segment => {

  const [segmentMin, segmentMax] = segment.split('-');

  const [rangeMin, rangeMax] = sliderRange;

  return (

    (parseInt(segmentMin) < parseInt(rangeMin) && parseInt(segmentMax) >= parseInt(rangeMin)) ||

    (parseInt(segmentMin) >= parseInt(rangeMin) && parseInt(segmentMax) <= parseInt(rangeMax)) ||

    (parseInt(segmentMin) <= parseInt(rangeMax) && parseInt(segmentMax) > parseInt(rangeMax))

  );

});

console.log(priceSegmentsMatchingRange_arrayOfStrings);


// if you want an array of arrays of strings (e.g. [["20", "50"], ["51", "100"]])

const priceSegmentsMatchingRange_arrayArraysOfStrings = priceSegments.filter(segment => {

  const [segmentMin, segmentMax] = segment.split('-');

  const [rangeMin, rangeMax] = sliderRange;

  return (

    (parseInt(segmentMin) < parseInt(rangeMin) && parseInt(segmentMax) >= parseInt(rangeMin)) ||

    (parseInt(segmentMin) >= parseInt(rangeMin) && parseInt(segmentMax) <= parseInt(rangeMax)) ||

    (parseInt(segmentMin) <= parseInt(rangeMax) && parseInt(segmentMax) > parseInt(rangeMax))

  );

}).map(segment => segment.split('-'));

console.log(priceSegmentsMatchingRange_arrayArraysOfStrings);


// if you want an array of arrays of numbers (e.g. [[20, 50], [51, 100]])

const priceSegmentsMatchingRange_arrayArraysOfNumbers = priceSegments.filter(segment => {

  const [segmentMin, segmentMax] = segment.split('-');

  const [rangeMin, rangeMax] = sliderRange;

  return (

    (parseInt(segmentMin) < parseInt(rangeMin) && parseInt(segmentMax) >= parseInt(rangeMin)) ||

    (parseInt(segmentMin) >= parseInt(rangeMin) && parseInt(segmentMax) <= parseInt(rangeMax)) ||

    (parseInt(segmentMin) <= parseInt(rangeMax) && parseInt(segmentMax) > parseInt(rangeMax))

  );

}).map(segment => segment.split('-').map(item => parseInt(item)));

console.log(priceSegmentsMatchingRange_arrayArraysOfNumbers);


查看完整回答
反對(duì) 回復(fù) 2023-03-03
?
繁花如伊

TA貢獻(xiàn)2012條經(jīng)驗(yàn) 獲得超12個(gè)贊

你可以使用array.filter

例如:

allValues = [

  { val: 5, count: 2}, 

  { val: 6, count: 2}, 

  { val: 7, count: 2}, 

  { val: 8, count: 2}, 

  { val: 9, count: 2}, 

  { val: 10, count: 3}

];

  

var sliderStartVal = 6;

var sliderEndVal = 9;

  

console.log(allValues.filter(x => x.val > sliderStartVal && x.val < sliderEndVal));


// Gives [{"val":7,"count":2},{"val":8,"count":2}]


查看完整回答
反對(duì) 回復(fù) 2023-03-03
?
富國(guó)滬深

TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊

如果我正確理解你想要實(shí)現(xiàn)的目標(biāo),你只需要使用Array.prototype.filter()(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)。


[編輯] 我仍然不是 100% 確定我得到了你想要實(shí)現(xiàn)的目標(biāo),但據(jù)我所知,這個(gè)編輯過的片段可能是你需要的。


/*

 * NOTES:

 * I think there are a couple of logical error I eliminated in this code snippet

 *   1. price segments should not overlap

 *   2. it should not be possible to select a price lower/higher than the lowes/highest price segment

 */


const priceSegments = ['20-50', '51-100']; // originally was ['20-50', '50-100'] see note (1.)

const sliderRange = [20, 50]; // originally was [1, 50] - see note (2.)

const pricesList = [{

    value: 30.5,

    count: 2

  },

  {

    value: 27.7,

    count: 1

  },

  {

    value: 50.0,

    count: 2

  },

  {

    value: 55.5,

    count: 2

  }

];


const priceRange = priceSegments.reduce((outObj, segment) => {

  /*

   * if the slider minimum falls within the segment,

   * set the minPrice to the segment minumum

   */

  if (

    parseInt(segment.split('-')[0]) <= parseInt(sliderRange[0]) &&

    parseInt(segment.split('-')[1]) >= parseInt(sliderRange[0])

  ) {

    outObj.minPrice = parseInt(segment.split('-')[0]);

  }


  /*

   * if the slider maximum falls within the segment,

   * set the maxPrice to the segment maximum

   */

  if (

    parseInt(segment.split('-')[0]) <= parseInt(sliderRange[1]) &&

    parseInt(segment.split('-')[1]) >= parseInt(sliderRange[1])

  ) {

    outObj.maxPrice = parseInt(segment.split('-')[1]);

  }

  return outObj;

}, {

  minPrice: 0,

  maxPrice: 0

});


const {

  minPrice,

  maxPrice

} = priceRange;

const pricesInRange = pricesList.filter((price) => price.value >= minPrice && price.value <= maxPrice);


console.log(pricesInRange);


查看完整回答
反對(duì) 回復(fù) 2023-03-03
  • 3 回答
  • 0 關(guān)注
  • 142 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)