javascript - How to get entries between a price x and y? -
javascript - How to get entries between a price x and y? -
im using current jquery ui slider range: http://jqueryui.com/slider/#range
and underscore.js http://underscorejs.org/
so ive minimum , max send, after user stopped slide function:
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]); },
in afterslide function min/max correctly, dont know how utilize underscore.js entries have cost starting min , end max.
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" } ] } };
after im using slider have min/max [12,61] want see entries starting cost between 12 , 61 $
var result = _.find(sample.response.things, min/max);??
i dont understand _.range() function correctly utilize how need, or create right statement .where/.find() function.
i'd max , min values, , since seems rather trivial i'd iterate object , check if relevant value within range, , add together new object, no _underscore needed really, this:
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; } }) },
javascript jquery jquery-ui underscore.js
Comments
Post a Comment