jQuery-HTML:将两个多个Feed显示为一个

时间:2015-11-07 11:33:04

标签: javascript jquery html feed

所以,我试图合并两个Feed,并按时间排序显示在两列中,从左上角开始最新,右下角最旧。确切地说,这是我想要的顺序:

------------------------
Newest     | 4th Newest
2nd Newest | 5th Newest
3rd Newest | 6th Newest 
------------------------

问题是,以下代码不起作用,并返回错误

Uncaught TypeError: item is not a function  (index:329)

我使用的代码如下。

<script>
  $(document).ready(function() {
    var blogFeed = $.ajax({
      type: "GET",
      url: "http://www.foxinflame.tk/blog/feed",
      dataType: "xml"
    })
    var videoFeed = $.ajax({
      type: "GET",
      url: "/videoFeed.php",
      dataType: "xml"
    })
    $.when(blogFeed, videoFeed).done(function(blogXML, videoXML){
//The one below this one is the 329 line
      var combinedXML = $(blogXML).find("item").concat(videoXML.find("entry"));
      var sortedXML = combinedXML.sort(function(videoFeedCompare, blogFeedCompare){
        var videoFeedDate = Date.parse(videoFeedCompare.find("published"));
        var blogFeedDate = Date.parse(blogFeedCompare.find("pubDate"));
        return videoFeedDate - blogFeedDate;
      });
      console.log(sortedXML.item(0));
      sortedXML.forEach(function(eachCounter) {
        console.log("stuff");
        var title = $(this).find("title").text();
        console.log(title);
        var description = $(this).find("description").text();
        var comments = +($(this).find("slash:comments").text());
        var pubDate = $(this).find("pubDate").text();
        var link = $(this).find("link").text();
        if(eachCounter < 3){
                  $("#firstColumnOfItems").append("<div class='postCollection'><div class='z-depth-1 blogpost' style='min-height: 300px'><br><h5><a style='color:black' href='"+link+"'>"+title+"</a></h5><br><p>"+description+"<br><i>"+comments+" Comments. Published at "+pubDate+"</i></p></div></div>");
                } else if(eachCounter < 6) {
                  $("#secondColumnOfItems").append("<div class='postCollection'><div class='z-depth-1 blogpost' style='min-height: 300px'><br><h5><a style='color:black' href='"+link+"'>"+title+"</a></h5><p>"+description+"<br><i>"+comments+" Comments. Published at "+pubDate+"</i></p></div></div>");
                }
      });
    });
  })
</script>

请注意,VideoFeed.php只是file_get_contents并回复它,因为JS无法做到(没有访问控制允许原始标题存在)。

出了什么问题,我该如何解决?

1 个答案:

答案 0 :(得分:1)

console.log(sortedXML.item(0));更改为console.log(sortedXML.item[0]);