【问题标题】:Sort date in rss from the latest从最新的 rss 中排序日期
【发布时间】:2017-08-04 03:40:56
【问题描述】:

我应该如何对日期进行排序(最新在顶部)?
目前,日期未排序。

下面是我的 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);
  }

});

【问题讨论】:

  • 对于来自 Google 的 RSS,您“应该”能够将 &amp;scoring=n&amp;scoring=d 添加到 URL 以首先获取最新信息,但它似乎不起作用。

标签: javascript jquery html rss


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-31
    • 2021-04-30
    • 2016-10-23
    • 2016-08-10
    • 1970-01-01
    • 2019-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多