我有一个场景,我从 jQuery 日历中选择一个日期,然后通过 ajax 遍历 JSON 文件。我的问题是由于使用了日期范围而出现的,例如,请参阅startdate和enddate:
{ "campus" : "A", "periods": [
{ "startdate" : "2013-01-02",
"enddate" : "2013-01-06",
"labels" : [
{ "Wednesday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Thursday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Friday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Saturday":
{ "00:00" : "Closed"
},
"Sunday":
{ "00:00" : "Closed"
}
}]
},
{ "startdate" : "2013-01-07",
"enddate" : "2013-03-24",
"labels" : [
{ "Monday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Tuesday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Wednesday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Thursday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Friday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Saturday":
{ "00:00" : "Closed"
},
"Sunday":
{ "00:00" : "Closed"
}
}]
}
从上面的代码片段可以看出,开始日期和结束日期是一个范围。我想知道最好的方法是尝试从 JSON 文件的范围内选择一个日期。
我考虑过使用 PHP分解来分解传递给 ajax 的日期,然后通过比较分解的参数与 startdate 和 enddate 中的数据来返回原始页面。我想知道是否分解日期然后在 startdate 和 enddate 之间迭代以查看日期是否匹配有效?
如果我的上述想法行不通,还有什么其他方法可行?