1 /*将时间装入数组arrTime里*/ 2 for (var i = 0; i < data.list.length; i++) { 3 if (data.list[i].LastDownLoadDataTime != null) { 4 arrTime.push(Mail_Common.Convert.dateToString(Mail_Common.Convert.jsonStrToDate(data.list[i].LastDownLoadDataTime))); 5 6 } 7 } 8 /*对数组arrTime进行去重复操作*/ 9 for (var i = 0; i < arrTime.length; i++) { 10 if (!uq[arrTime[i]]) { 11 uq[arrTime[i]] = true; 12 rq.push(arrTime[i]); 13 } 14 } 15 /*从低到高排序*/ 16 rq = rq.sort(); 17 /*反转——从高到低*/ 18 rq = rq.reverse(); 19 20 /*把数组rq数据对列表数据进行比较*/ 21 for (var i = 0; i < rq.length; i++) { 22 strs += '<h1 class="fj-date">' + rq[i] + '</h1>'; 23 strs += ' <div class="fj-pic">'; 24 for (var j = 0; j < data.list.length; j++) { 25 26 time1 = rq[i]; 27 time2 = Mail_Common.Convert.dateToString(Mail_Common.Convert.jsonStrToDate(data.list[j].LastDownLoadDataTime)); 28 29 if (time1 == time2) { 30 strs += ' <a href="javascript:;" msgid="' + data.list[j].AutoID + '">' + data.list[j].MailAttachmentFileName + '</a> '; 31 } 32 } 33 34 strs += '</div>'; 35 } 36 37 $(".fj-list").html(strs);
下面是html灵活使用的写法:实现一样的功能
1 for (var i = 0; i < data.list.length; i++) { 2 if (data.list[i].LastDownLoadDataTime != null) { 3 var time = WriteEvent.JsonToTime(data.list[i].LastDownLoadDataTime); 4 if ($("h1.fj-date[time='" + time + "']").length == 0) { 5 $(".fj-list").append('<h1 class="fj-date" time="' + time + '">' + time + '</h1>'); 6 } 7 if ($("h1.fj-date[time='" + time + "']").next("div.fj-pic").length == 0) { 8 $(".fj-list").append('<div class="fj-pic"></div>'); 9 } 10 $("h1.fj-date[time='" + time + "']").next().append('<a href="javascript:;" msgid="' + data.list[i].AutoID + '">' + data.list[i].MailAttachmentFileName + '</a>'); 11 } 12 }