您好我想從一個動態填充的列表中完成表格行 - 表格單元格日期之後tr/td數據附加到表中的tbody。排序()函數後appendTo tbody
這跟隨我的問題在這裏:JavaScript Sort by Date on table not working其中我已成功排序日期。
感謝
var dates = jQuery('tr.Entries').find('td.event-date > a').map(function() {
return jQuery(this).text();
}).get();
dates.sort(function(a,b){
var dateA = a;
dateA = dateA.replace(/(..)\/(..)\/(....)/, '$2-$1-$3');
var dateB = b;
dateB = dateB.replace(/(..)\/(..)\/(....)/, '$2-$1-$3');
return new Date(dateA).getTime() - new Date(dateB).getTime();
});
jQuery.each(dates, function (index, value) {
//how to append back to tbody?
console.log(value);
});
下面是一些條目(還有很多更 - 動態填充行)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
<table class="event clearfix">
<thead>
<tr>
<td>Date</td>
<td>Event</td>
<td>Location</td>
<td>Ticket</td>
</tr>
<tr class="space"></tr>
</thead>
<tbody>
<tr class="Entries">
<td class="event-date">
<a href="#">25/08/2017</a>
</td>
<td class="event-title">
<a href="#">Live N Local Winter Music Festival</a>
</td>
<td class="event-location">
<a href="#">Pause Bar, Balaclava</a>
</td>
<td class="event-ticket-link">
<a href="#" class="button button-normal">BUY TICKET</a>
</td>
</tr>
<tr class="Entries">
<td class="event-date">
<a href="#">15/04/2017</a>
</td>
<td class="event-title">
<a href="#">Reggae, Seggae & Sega Night</a>
</td>
<td class="event-location">
<a href="#">Bar Open, Fitzroy Melbourne</a>
</td>
<td class="event-ticket-link">
<a href="#" class="button button-normal">BUY TICKET</a>
</td>
</tr>
<tr class="Entries">
<td class="event-date">
<a href="#">06/05/2016</a>
</td>
<td class="event-title">
<a href="#">The Sunraysia Multicultural Festival</a>
</td>
<td class="event-location">
<a href="#">Nowingi Place, Mildura Victoria</a>
</td>
<td class="event-ticket-link">
<a href="#" class="button button-normal">BUY TICKET</a>
</td>
</tr>
</tbody>
</table>
我不是一個實驗JS的用戶,但如果他們沒有那麼多的條目,我只想把它們全部並附加回 – efkin