list.jsでソートしたらhtmlが消える
list.jsを使ってテーブルをソートしたらテーブルの中身が全部消えます。何故でしょうか...
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="../scripts/script.js"></script>
<body>
<div id='itemlist'>
<button class='sort desc' data-sort='date'>Sort By Date</button>
<table>
<tbody class='list'>
</tbody>
</table>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/list.js/1.5.0/list.min.js"></script>
<script type='text/javascript'>
var options = {
// 検索するターゲットデータ
valueNames: [ 'date', 'elem' ]
};
// ターゲットとなるID
var itemList = new List('itemlist', options);
</script>
</body>
</html>
$(function() {
var url = ["all-c_int.xml","all-dom.xml"];
var feed = new Object();
$.each(url, function(index, value){
$.ajax({
url: value,
type:"GET",
dataType:"xml",
timeout:1000,
xhrFields: {
withCredentials: true
},
cache: false,
error:function(){
alert("Failed to load XML");
},
success:function(xml){
$(xml).find("item").each(function(){
var item_link=$(this).find("link").text();
var item_title=$(this).find("title").text();
var item_desc=$(this).find("description").text();
var item_date=dateParse($(this).find('pubDate').text());
feed[item_date] = "<tr><td class='date'>"+item_date+"</td><td class='elem'><a href='"+item_link+"'>"+item_title+"</a>"+item_desc+"</td></tr>";
if(item_title!="") $(feed[item_date]).appendTo("tbody");
});
}
});
});
function dateParse(str){
var dateObject = new Date(str);
year = dateObject.getFullYear();
month = dateObject.getMonth();
day = dateObject.getDate();
hour = dateObject.getHours();
minute = dateObject.getMinutes();
second = dateObject.getSeconds();
if (month < 10) { month ="0" + month; }
if (day < 10) { day = "0" + day; }
if (hour < 10) { hout = "0" + hour; }
if (minute < 10) { minute = "0" + minute; }
if (second < 10) { second = "0" + second; }
return year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" + second + " ";
}
});