js

//获取log信息
				getLogData:function(){
					var that = this;
                    var url = "/_api/web/Lists/getbytitle('historyLog')/items";
                    ajax_tool(url,'','get', function (data) {

                    	var temp = data.d.results;
                    	var map = {},
						dest = [];
						for(var i = 0; i < temp.length; i++){
						    var ai = temp[i];
						    if(!map[ai.projectName]){
						        dest.push({
						            projectName: ai.projectName,
						            data: [ai]
						        });
						        map[ai.projectName] = ai;
						    }else{
						        for(var j = 0; j < dest.length; j++){
						            var dj = dest[j];
						            if(dj.projectName == ai.projectName){
						                dj.data.push(ai);
						                break;
						            }
						        }
						    }
						}
						var logList = [];
						var titleArray = ["No","Project Name","Status","Operator","Action_Date","Action_Comments","Budget"];
						logList.push(titleArray);
						var tempLogList = [];
						for(var m=0; m<dest.length; m++){
							tempLogList = tempLogList.concat(dest[m].data.sort(function(a,b){return a.actionDate > b.actionDate ? 1 : -1}));
						}
						for(var n=0; n<tempLogList.length; n++){
							var rowData = [
								n+1,
								tempLogList[n].projectName,
								tempLogList[n].projectStatus,
								tempLogList[n].operator,
								(tempLogList[n].actionDate ? that.formatDate1(tempLogList[n].actionDate) : ""),
								(tempLogList[n].actionComments ? tempLogList[n].actionComments : ""),
								(tempLogList[n].budget ? tempLogList[n].budget : "")
							]
							logList.push(rowData);
						}

						var ws_name = "HistoryLog";
					    var wb = new Workbook(), 

					    ws = sheet_from_array_of_arrays(logList);
					    ws['!cols'] = [{'wch': 5},{'wch': 25},{'wch': 10},{'wch': 20},{'wch': 25},{'wch': 25},{'wch': 10}];
						 
						/* add worksheet to workbook */
						wb.SheetNames.push(ws_name);
						wb.Sheets[ws_name] = ws;
						var wbout = XLSX.write(wb, {bookType:'xlsx', bookSST:true, type: 'binary'});
					
						saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), "HistoryLog.xlsx")
						that.downloadExcelDisabled = false;
                    	console.log(logList);                      
                    }, function (data) {
                        console.log(data);
                    });
				}
学贵有恒,而行胜于言
原文地址:https://www.cnblogs.com/huangbinlooksgood/p/14203887.html