2012-11-23 42 views
-1

我有標題,圖像和日期的列表視圖。我想根據日期字段對該列表進行排序,然後顯示在html5頁面中。我在這上面使用了jquery和html5。在javascript中排序listview

$j('#task_summary_list').empty(); 

if (response.totalSize > 0) { 
    $j.each(response.records, function(i, record) { 
     var imgName; 
     switch (record.Priority) { 
      case "High": 
       imgName = "images/prio_high24.png"; 
       break; 
      case "Low": 
       imgName = "images/prio_low24.png"; 
       break; 
      default: 
       imgName = "images/prio_normal24.png"; 
     } 

     // create new list entry for record to the listview 
     $j('<li></li>') 
     .attr('id', record.Id) 
     .hide() 
     .append(
       '<a href="#">' + '<img src="' + imgName 
       + '" alt="High" class="ui-li-icon">' 
       + '<h1>' 
       + record.Subject + '</h1>' 
       + '<p>' + '<strong>' 
       + record.ActivityDate + '</strong>' + '</p>' 
       + '</a>') 
     .click(function(e) { 
      e.preventDefault(); 

      console.log("Under onSuccessTasks " + record.Id); 
      showTaskDetails(record); 
     }) 
     .appendTo('#task_summary_list') 
     .show(); 
    }); 
} 
else { 
    $j('<li class="norecord">No records to display</li>').appendTo('#task_summary_list'); 
} 

$j('#task_summary_list').listview('refresh'); 

$j.mobile.hidePageLoadingMsg(); 

任何幫助表示讚賞。 非常感謝。

+1

哪裏的代碼? – elclanrs

回答

0
$('#dateDiv').sortElements(function(a, b){ 
    return Date.parse($(a).text()) > Date.parse($(b).text()) ? 1 : -1; 
}); 
0

在我的應用程序中,我使用sql查詢,因此我在主查詢後使用OrderBy子句,數據以排序形式顯示在UI上。

謝謝