The code below is filling the dropdown menu with time-based options based on a condition. The problem is that the sorting order is wrong: when I add 10 am
to 1 pm
, it is working fine. When I update the time and add another am
time, then it shows below pm
.
for (var i = 0; i < data.times.length; i++) {
//var timeFrom = new Date(data.times[i].TimeFrom)
var timeTo = new Date(data.times[i].TimeTo)
var iTime = new Date(data.times[i].TimeFrom)
console.log(data.times[i].diffrence);
while (timeTo >= iTime) {
var formate = iTime.toLocaleTimeString();
//data.times[i].PK_ID
var option = '<option value="' + formate + '">' + formate + '</option>';
$('#times').append(option).sortable();
iTime.setMinutes(iTime.getUTCMinutes() + data.times[i].diffrence)
}
}
question from:
https://stackoverflow.com/questions/65949063/how-to-sort-dropdown-menu-with-am-and-pm-times-in-jquery 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…