按日期分组XML数据并使用JQuery输出到HTML
我正在寻找有关将共享同一日期的XML数据分组并将其输出到HTML表中的帮助。到目前为止,我从GoogleSheets生成的XML文件中提取数据,并将其显示在表中,但当循环遍历整个XML文件时,同一日期将被输出多次 这是从我的Google工作表生成的XML示例按日期分组XML数据并使用JQuery输出到HTML,html,jquery,xml,grouping,Html,Jquery,Xml,Grouping,我正在寻找有关将共享同一日期的XML数据分组并将其输出到HTML表中的帮助。到目前为止,我从GoogleSheets生成的XML文件中提取数据,并将其显示在表中,但当循环遍历整个XML文件时,同一日期将被输出多次 这是从我的Google工作表生成的XML示例 <entry> <id>https://spreadsheets.google.com/feeds/list/myID/2/public/values/cokwr</id> <upd
<entry>
<id>https://spreadsheets.google.com/feeds/list/myID/2/public/values/cokwr</id>
<updated>2020-09-18T19:21:44.407Z</updated>
<category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#list'/>
<title type='text'>1</title>
<content type='text'>dt: 12/09/2020 12:30, date: 12-Sep-20, time: 12:30, location: Craven Cottage, hometeam: Fulham, awayteam: Arsenal, homeresult: 0, awayresult: 3</content>
<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/myID/2/public/values/cokwr'/>
<gsx:rdno.>1</gsx:rdno.>
<gsx:dt>12/09/2020 12:30</gsx:dt>
<gsx:date>12-Sep-20</gsx:date>
<gsx:time>12:30</gsx:time>
<gsx:location>Craven Cottage</gsx:location>
<gsx:hometeam>Fulham</gsx:hometeam>
<gsx:awayteam>Arsenal</gsx:awayteam>
<gsx:homeresult>0</gsx:homeresult>
<gsx:awayresult>3</gsx:awayresult>
</entry>
<entry>
<id>https://spreadsheets.google.com/feeds/list/myID/2/public/values/cpzh4</id>
<updated>2020-09-18T19:21:44.407Z</updated>
<category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#list'/>
<title type='text'>1</title>
<content type='text'>dt: 12/09/2020 15:00, date: 12-Sep-20, time: 15:00, location: Turf Moor, hometeam: Burnley, awayteam: Man Utd, homeresult: P, awayresult: P</content>
<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/list/myID/2/public/values/cpzh4'/>
<gsx:rdno.>1</gsx:rdno.>
<gsx:dt>12/09/2020 15:00</gsx:dt>
<gsx:date>12-Sep-20</gsx:date>
<gsx:time>15:00</gsx:time>
<gsx:location>Turf Moor</gsx:location>
<gsx:hometeam>Burnley</gsx:hometeam>
<gsx:awayteam>Man Utd</gsx:awayteam>
<gsx:homeresult>P</gsx:homeresult>
<gsx:awayresult>P</gsx:awayresult>
</entry>
https://spreadsheets.google.com/feeds/list/myID/2/public/values/cokwr
2020-09-18T19:21:44.407Z
1.
dt:12/09/2020 12:30,日期:20年9月12日,时间:12:30,地点:克雷文别墅,主队:富勒姆,awayteam:阿森纳,本垒成绩:0,awayresult:3
1.
12/09/2020 12:30
20年9月12日
12:30
克拉文农场球场
富勒姆
兵工厂
0
3.
https://spreadsheets.google.com/feeds/list/myID/2/public/values/cpzh4
2020-09-18T19:21:44.407Z
1.
dt:12/09/2020 15:00,日期:20年9月12日,时间:15:00,地点:草皮沼地,主队:伯恩利,awayteam:Man Utd,主队成绩:P,awayresult:P
1.
12/09/2020 15:00
20年9月12日
15:00
草坪沼地
伯恩利
曼联
P
P
我拉取数据并显示它的脚本如下所示:
<script>
$(document).ready(function(){
$.ajax({
type: "GET",
url: "https://spreadsheets.google.com/feeds/list/myID/2/public/values",
dataType: "html",
success: function(xml){
console.log("here");$
$(xml).find('entry').each(function(){
const parser = new DOMParser();
for(var i = 0; i<xml.length; i++){
var xmlDom = parser.parseFromString(xml, 'text/xml');
var date = xmlDom.getElementsByTagName('gsx:date')[i].textContent;
var hometeam = xmlDom.getElementsByTagName('gsx:hometeam')[i].textContent;
var homeresult = xmlDom.getElementsByTagName('gsx:homeresult')[i].textContent;
var awayresult = xmlDom.getElementsByTagName('gsx:awayresult')[i].textContent;
var awayteam = xmlDom.getElementsByTagName('gsx:awayteam')[i].textContent;
$('#mytable tr:last').after('<tr><td>'+date+'</td></tr><tr><td>'+hometeam+'</td><td>'+homeresult+'</td><td>'+awayresult+'</td><td>'+awayteam+'</td></tr>');
}
});
}
});
$(文档).ready(函数(){
$.ajax({
键入:“获取”,
url:“https://spreadsheets.google.com/feeds/list/myID/2/public/values",
数据类型:“html”,
成功:函数(xml){
console.log(“此处”)$
$(xml).find('entry').each(function(){
const parser=new DOMParser();
对于(var i=0;i