How should I sort the date (latest at the top)?
Currently, the date is not sorted.
Below is my JSFiddle:
$(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);
}
});
You import a FeedEk.js
in your javaScript file to fetch data and render your dom elements for creating a list. You can sort data before rendering like this:
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()
})
来源:https://stackoverflow.com/questions/45497903/sort-date-in-rss-from-the-latest