Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

sorting - How to sort dropdown menu with AM and PM times in jQuery?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...