list.jsを使ってテーブルをソートしたらテーブルの中身が全部消えます。何故でしょうか...
html<!DOCTYPE
1<html lang="ja"> 2<head> 3<meta charset="utf-8"> 4 <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"> 5 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 6 <script src="../scripts/script.js"></script> 7<body> 8 <div id='itemlist'> 9 10 <button class='sort desc' data-sort='date'>Sort By Date</button> 11 12 <table> 13 <tbody class='list'> 14 15 </tbody> 16 </table> 17 </div> 18 19 <script src="//cdnjs.cloudflare.com/ajax/libs/list.js/1.5.0/list.min.js"></script> 20 <script type='text/javascript'> 21 var options = { 22 // 検索するターゲットデータ 23 valueNames: [ 'date', 'elem' ] 24 }; 25 26 // ターゲットとなるID 27 var itemList = new List('itemlist', options); 28 </script> 29</body> 30</html> 31 32
javascript
1$(function() { 2 3 var url = ["all-c_int.xml","all-dom.xml"]; 4 var feed = new Object(); 5 6 $.each(url, function(index, value){ 7 8 $.ajax({ 9 url: value, 10 type:"GET", 11 dataType:"xml", 12 timeout:1000, 13 xhrFields: { 14 withCredentials: true 15 }, 16 cache: false, 17 error:function(){ 18 alert("Failed to load XML"); 19 }, 20 success:function(xml){ 21 $(xml).find("item").each(function(){ 22 var item_link=$(this).find("link").text(); 23 var item_title=$(this).find("title").text(); 24 var item_desc=$(this).find("description").text(); 25 var item_date=dateParse($(this).find('pubDate').text()); 26 feed[item_date] = "<tr><td class='date'>"+item_date+"</td><td class='elem'><a href='"+item_link+"'>"+item_title+"</a>"+item_desc+"</td></tr>"; 27 if(item_title!="") $(feed[item_date]).appendTo("tbody"); 28 29 }); 30 } 31 }); 32 33 }); 34 35 function dateParse(str){ 36 var dateObject = new Date(str); 37 year = dateObject.getFullYear(); 38 month = dateObject.getMonth(); 39 day = dateObject.getDate(); 40 hour = dateObject.getHours(); 41 minute = dateObject.getMinutes(); 42 second = dateObject.getSeconds(); 43 44 if (month < 10) { month ="0" + month; } 45 if (day < 10) { day = "0" + day; } 46 if (hour < 10) { hout = "0" + hour; } 47 if (minute < 10) { minute = "0" + minute; } 48 if (second < 10) { second = "0" + second; } 49 50 return year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" + second + " "; 51 } 52 53}); 54
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。