过滤任何日期范围内的JSON数据 [英] Filtering data in JSON for any date range

查看:49
本文介绍了过滤任何日期范围内的JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式的json文件:

I have a json file in the following format:

    [
  {
    "date_hour": "2014-04-30T18:30:00Z",
    "metric": 6986,
    "metric_ly": 4337,
    "mv": "OTHERS",
    "time_period": "Daily",
    "platform": "MWEB",
    "visits": 8624,
    "pv_visits": 6879,
    "atc_visits": 335,
    "ic_visits": 0,
    "orders": 72
  },
  {
    "date_hour": "2014-04-30T18:30:00Z",
    "metric": 5556372,
    "metric_ly": 3843986,
    "mv": "SEO",
    "time_period": "Daily",
    "platform": "CORESITE",
    "visits": 2005259,
    "pv_visits": 1043922,
    "atc_visits": 130590,
    "ic_visits": 64320,
    "orders": 53760
  }
  ]

我需要一个日期滑块或selecor(或任何GUI,最好是使用javascript构建的一个GUI),通过它可以针对给定的日期范围过滤此JSON文件的数据.关于应该使用哪个库的任何建议?

I need a date slider or selecor(or any GUI,one that preferably is built using javascript) using which the data of this JSON file can be filtered for a given range of dates. Any suggestions as to which library should I use?

推荐答案

找到一个喜欢的Silder小部件(那里有几十个),并假设您的滑块小部件提供了两个日期值(startDate和endDate),我会使用 underscore.js 用于类似这样的事情:

Find a silder widget to your liking (there are dozens out there), and assuming your slider widget provides two date values (startDate and endDate), I would use underscore.js for something like this:

var filteredDates = _.filter(values, function(value){ 
    return (value.date_hour.getTime() > startDate.getTime() &&  
        value.date_hour.getTime() < endDate.getTime())
});

这篇关于过滤任何日期范围内的JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆