我从DatePicker(结束,开始)获取两个值。我想过滤数据并在这两个值之间获取数据。如何使用JS/Jquery过滤日期和JSon数据
但我无法让它工作的写作方式。
要专注于这个问题,让我们考虑一下(开始日期和结束日期)
// Here I want to
//var myDate = new Date();
var startDate = new Date(2013, 1, 28);
var endDate = new Date(2013, 1, 30);
我的数据是既像值:
var filter_data = {
"type": "FeatureCollection",
"features": [{
"geometry": {
"type": "Point",
"coordinates": [-73.98115508098644, 40.755304404503995]
},
"type": "Feature",
"id": 0,
"properties": {
"Date": "01/20/2013 08:58:03 PM",
"lat": 40.755304404503995,
"lon": -73.98115508098644,
"Address": "33 WEST 44 STREET"
}
},, {
"geometry": {
"type": "Point",
"coordinates": [-73.968253883967947, 40.765050901514641]
},
"type": "Feature",
"id": 1,
"properties": {
"Date": "01/29/2013 02:53:11 PM",
"lat": 40.765050901514641,
"lon": -73.968253883967947,
"Address": "564 PARK AVENUE"
}
},
]
};
要过滤数据,我用两种不同的方法,但这些方法都不起作用。
var filteredData_2 = filter_data.where((n, i) => n.properties.Date <startDate && n.properties.endDate) ;
var filteredData = filter_data.filter(function(a){return a.properties.Date >startDate && a.properties.Date <endDate;});
console.log(filteredData_2)
console.log(filteredData)
这里是喜欢的jsfiddle:
它应该是 “>的startDate” 而不是 “<的startDate”。纠正我,如果我错了 – user3378649
是的,你是对的! – DeeDee
感谢您的出色解释。非常感谢 – user3378649