快速提问地点总是布伦特伍德、士麦那和斯普林希尔,是否总是按此顺序填充可用时间的列表?现在位置会根据可用时间而变化,这意味着如果士麦那的位置有下一个可用时间,它将首先列出。——</p>
JSON 文件的链接https://www.inquicker.com/facility/americas-family-doctors.json
这是我的小提琴链接: http: //jsfiddle.net/qUvuB/11/用于下面的代码,这是我的小提琴链接,用于显示位置、医生和时间的代码:jsfiddle.net/mccannf/qUvuB/ 6/
这是我到目前为止的代码:
我很感激这方面的任何帮助。
<!DOCTYPE html>
<html>
<head>
<title>AFD TEST MOD</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script>
<script>
$(document).ready(function(){
$.getJSON('https://www.inquicker.com/facility/americas-family-doctors.json',
function(data){
var earliest = {};
var doctor = {};
var links = {};
$.each(data.schedules, function(i, name) {
var location = name.name.split(' - ')[0];
var dr_name = name.name.split(' - ')[1];
if (name.available_times.length) {
if (location in earliest) { // location has already been stored.
var newTime = parseAvailableDate(name.available_times[0].when);
if (newTime.isBefore(earliest[location])) {
earliest[location] = newTime;
doctor[location] = dr_name;
links[location] = name.available_times[0].url;
}
}
else {
earliest[location] = parseAvailableDate(name.available_times[0].when);
doctor[location] = dr_name;
links[location] = name.available_times[0].url;
}
}
});
for (i in earliest) {
$("#names").append("<li><a href='"+links[i]+"'>"+earliest[i].toString("dd/yyyy h:mm tt")+"</a></li>");
}
});
});
function parseAvailableDate(dateString) {
var trimmedString = dateString.replace(/^\s\s*/, '');
var avTime=trimmedString.split(' ')[0],
ampm=trimmedString.split(' ')[1],
avDay=trimmedString.split(' ')[2];
var avDate = Date.parse("next "+avDay);
avDate.addHours(avTime.split(':')[0]).addMinutes(avTime.split(':')[1]);
if (ampm == "pm" && avTime.split(':')[0] != "12") avDate.addHours(12);
return avDate;
}
</script>
</head>
<body>
<ul id="names"></ul>
</body>
</html>