Javascript jQuery HTML:将两个多个提要显示为一个提要
因此,我尝试合并两个提要,并按时间排序,在两列中显示它,从左上角的最新提要开始,从右下角的最旧提要开始。准确地说,这是我想要的顺序:Javascript jQuery HTML:将两个多个提要显示为一个提要,javascript,jquery,html,feed,Javascript,Jquery,Html,Feed,因此,我尝试合并两个提要,并按时间排序,在两列中显示它,从左上角的最新提要开始,从右下角的最旧提要开始。准确地说,这是我想要的顺序: ------------------------ Newest | 4th Newest 2nd Newest | 5th Newest 3rd Newest | 6th Newest ------------------------ 问题是,以下代码不起作用,并返回了一个错误 Uncaught TypeError: item is not a fun
------------------------
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>
$(文档).ready(函数(){
var blogFeed=$.ajax({
键入:“获取”,
url:“http://www.foxinflame.tk/blog/feed",
数据类型:“xml”
})
var videoFeed=$.ajax({
键入:“获取”,
url:“/videoFeed.php”,
数据类型:“xml”
})
$.when(blogFeed,videoFeed).done(函数(blogXML,videoXML){
//这条线下面的是329线
var combinedXML=$(blogXML.find(“item”).concat(videoXML.find(“entry”));
var sortedXML=combinedXML.sort(函数(videoFeedCompare、blogFeedCompare){
var videoFeedDate=Date.parse(videoFeedCompare.find(“published”);
var blogFeedDate=Date.parse(blogfeedpare.find(“pubDate”);
返回videoFeedDate-blogFeedDate;
});
控制台日志(sortedXML.item(0));
sortedXML.forEach(功能(每个计数器){
控制台日志(“东西”);
var title=$(this.find(“title”).text();
控制台日志(标题);
var description=$(this.find(“description”).text();
var comments=+($(this).find(“斜杠:comments”).text();
var pubDate=$(this.find(“pubDate”).text();
var link=$(this.find(“link”).text();
如果(每个计数器<3){
$(“#firstColumnOfItems”)。追加(“
”+说明+”
“+评论+”评论。发布于“+pubDate+””);
}否则如果(每个计数器<6){
$(“#secondColumnOfItems”)。追加(“
”+说明+”
“+评论+”评论。发布于“+pubDate+””);
}
});
});
})
请注意,VideoFeed.php只是执行文件获取内容
并对其进行响应,因为JS无法执行此操作(不存在访问控制允许源标题)
出了什么问题,我该如何修复它?更改
console.log(sortedXML.item(0))代码>到控制台日志(sortedXML.item[0])代码>现在,它在带有Concat()
函数的行中返回“Entry不是函数”。它也不会将该项回显到控制台。您必须查看$(blogXML).find(“项”)
是否正在返回某些内容。无论如何,我认为.concat
不适用于jquery元素数组。也许您可以尝试其他方法,比如.push
,它看起来好像组合XML
不是数组。Foreach函数对它不起作用,当使用combinedXML===Array
进行检查时,它不会返回true。是的,我确实使用了Push。创建一个JSFIDLE,也许我可以帮你。只看代码很难看出这是真的。但是,由于我的代码使用来自其他网站的提要,“无访问控制允许源标题”会阻止代码在JSFIDLE上工作。