2013-02-11 28 views
0

即時通訊使用當前jQuery UI的滑塊與一個範圍: http://jqueryui.com/slider/#range如何獲得價格x和y之間的條目?

和underscore.js http://underscorejs.org/

所以香港專業教育學院一個最小和一個最大我發送,在用戶停止滑動至功能:

currentSlide:function(){ 
    $('#slider').slider({ 
     range: true, 
     min: min, 
     max: max, 
     values: [ vmin, vmax ], 
     stop:$.proxy(this.afterSlide,this) 
    }); 
}, 

afterSlide:function(event, ui) { 
    console.log(ui.values[0]); 
}, 
在afterSlide功能我得到正確的最小/最大

,但我不知道如何使用underscore.js獲得具有本分和最終由最高價格開始的所有條目。

Examplearray:

var sample = { 
    "response": { 
     "things": [{ 
      "index": 0, 
      "price": "10" 
     },{ 
      "index": 1, 
      "price": "15" 
     },{ 
      "index": 2, 
      "price": "60" 
     },{ 
      "index": 3, 
      "price": "10" 
     },{ 
      "index": 4, 
      "price": "100" 
     } 
     ] 
    } 
}; 
使用滑塊我有最小值/最大值[12,61],所以我希望看到所有條目僅與12之間的價格開始,61 $

var result = _.find(sample.response.things, min/max);?? 

IM後

我不明白_.range()函數正確使用它,我需要如何,或與.where/ .find()函數創建正確的語句。

+0

的可能重複(http://stackoverflow.com/questions/11697702/how-to-use-underscore-js -filter-with-an-object) – Phrogz 2013-02-11 17:19:04

+0

nope。它不是dublicate,因爲需要一個比較來獲得範圍之間的所有條目而不是一個鍵/值對 – JohnDoo 2013-02-11 17:21:58

回答

2

我只是得到最大和最小值,因爲這似乎很平凡我只是迭代對象,並檢查相關的值是否在範圍內,並將其添加到一個新的對象,沒有_underscore需要真的是這樣的:[?如何使用Underscore.js過濾器與對象]

afterSlide:function(event, ui) { 
    var min = ui.values[0], 
     max = ui.values[1], 
    items = {}; 

    $.each(sample.response.things[0], function(key, val) { 
     if (val.price > min && val.price < max) { 
      items[val.index] = val.price; 
     } 
    }) 
}, 
+0

非常感謝adeneo! – JohnDoo 2013-02-11 17:33:19

相關問題