【发布时间】:2016-02-08 12:19:04
【问题描述】:
所以,我试图合并两个提要,并将其显示在按时间排序的两列中,从左上角的最新开始,右下角最旧的开始。准确地说,这是我想要的顺序:
------------------------
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 无法执行此操作(不存在访问控制允许原始标头)。
出了什么问题,我该如何解决?
【问题讨论】:
标签: javascript jquery html feed