从最新的rss排序日期 [英] Sort date in rss from the latest
本文介绍了从最新的rss排序日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我应该如何排序日期(最新的排在最前面)?
目前,日期并未排序。
How should I sort the date (latest at the top)?
Currently, the date is not sorted.
以下是我的JSFiddle:
Below is my 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);
}
});
推荐答案
在javaScript文件中导入 FeedEk.js
以获取数据并呈现您的dom元素以创建列表。您可以像这样呈现数据之前对数据进行排序:
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()
})
这篇关于从最新的rss排序日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文