2017-08-04 48 views
0

我應該如何排序日期(最新的頂部)?
目前,日期未排序。rss從最新的排序日期

下面是我的jsfiddle:

http://jsfiddle.net/qoLg6dnu/

$(document).ready(function() { 

    $('#divRss').FeedEk({ 
    FeedUrl: 'https://www.google.com/finance/company_news?q=SGX:533&ei=EeiDWaGGMpXUuATxloPgAw&output=rss' 
    }); 

    var r = Math.floor(Math.random() * 256); 
    var g = Math.floor(Math.random() * 256); 
    var b = Math.floor(Math.random() * 256); 

    $('#example, .itemTitle a').css("color", getHex(r, g, b)); 

    $('#example').click(function() { 
    $('.itemTitle a').css("color", getHex(r, g, b)); 
    }); 

    function intToHex(n) { 
    n = n.toString(16); 
    if (n.length < 2) 
     n = "0" + n; 
    return n; 
    } 

    function getHex(r, g, b) { 
    return '#' + intToHex(r) + intToHex(g) + intToHex(b); 
    } 

}); 
+0

對於RSS從谷歌你「應該」能夠'&得分= N'或'&得分= D'添加到URL來先得到最新的,但它似乎並沒有工作。 – nnnnnn

回答

1

使用Array.prototype.sort()

在javaScript文件中導入FeedEk.js以獲取數據並呈現用於創建列表的dom元素。您可以渲染像在此之前的數據進行排序:

data.query.results.rss.sort(function(item1, item2) { 
    var d1 = new Date(item1.channel.item.pubDate) 
    var d2 = new Date(item2.channel.item.pubDate) 
    return d2.getTime() - d1.getTime() 
}) 

View all codes here