我有两个虚拟时间条目,它们从我的数据库带回到我的php页面中console.log
:
[{
"FIRST_NAME": "Kiera",
"LAST_NAME": "Long",
"USERNAME": "klong.thehelpers@gmail.com",
"CLOCK_IN": "2017-08-25 09:19:04",
"START_LUNCH": "0000-00-00 00:00:00",
"END_LUNCH": "0000-00-00 00:00:00",
"CLOCK_OUT": "2017-08-25 09:33:28",
"TOTAL_HRS": "00:00hr:14min:24s"
}, {
"FIRST_NAME": "Kiera",
"LAST_NAME": "Long",
"USERNAME": "klong.thehelpers@gmail.com",
"CLOCK_IN": "2017-11-12 10:59:59",
"START_LUNCH": "0000-00-00 00:00:00",
"END_LUNCH": "0000-00-00 00:00:00",
"CLOCK_OUT": "2017-11-12 11:39:13",
"TOTAL_HRS": "00:00hr:39min:14s"
}]
我正在使用jspdf和jspdf AutoTable 将这些结果以表格形式放入pdf中。每次,我生成一个pdf ,为每个时间条目创建一个单独的pdf文档。我需要的是让这两个条目打印在一个文档上并成为一个表中的行。
我也在努力提高编写函数的能力。这里是:
$.post('api/hoursprintoff.php', {
useremail: useremail,
startdate: startdate,
enddate: enddate
}, function(data) {
console.log(data);
var obj = JSON.parse(data);
var htmlToInsert = obj.map(function(item) {
var fname = item.FIRST_NAME;
var lname = item.LAST_NAME;
var username = item.USERNAME;
var startd = item.CLOCK_IN;
var totals = item.TOTAL_HRS;
var endd = item.CLOCK_OUT;
var username = item.USERNAME;
/*if (startd.length >1 && endd.length > 1) {
console.log(startd + " " + endd);
/*$.each(obj, function( key, value ) {
console.dir( key + ": " + JSON.stringify(value) );
});
}*/
//console.log(username);
//console.log(startd);
//console.log(endd);
//var columns = [{title: "Clock In", dataKey: "CLOCK_IN"}, {title: "Clock Out", dataKey: "CLOCK_OUT"}, {title: "Total Hours", dataKey: "TOTAL_HRS"}];
//var rows = {data} ;
//console.log(obj.length);
//console.log(item);
/*
function timesheet(timein, timeout, total) {
var columns = [{title: "Clock In", dataKey: "CLOCK_IN"}, {title: "Clock Out", dataKey: "CLOCK_OUT"}, {title: "Total Hours", dataKey: "TOTAL_HRS"}];
$.each(item, function( key, value ) {
console.log(key, value);
//var rows = [{'CLOCK_IN': timein, 'CLOCK_OUT': timeout, 'TOTAL_HRS': total}];
});
var doc = new jsPDF('p', 'pt');
//doc.createdCell: function (cell, data) { }
//doc.autoTable(columns, rows);
doc.text(20, 20, fname + " " + lname + "'s " + 'Timesheet!');
doc.text(20, 30, 'Organization Email: ' + username);
doc.save("Test.pdf");
}//end of timesheet function
*/
function timesheet(startd, endd, totals) {
var doc = new jsPDF('p', 'pt');
var columns = [{
title: "Clock In",
dataKey: "CLOCK_IN"
}, {
title: "Clock Out",
dataKey: "CLOCK_OUT"
}, {
title: "Total Hours",
dataKey: "TOTAL_HRS"
}];
var rows = [{
'CLOCK_IN': startd,
'CLOCK_OUT': endd,
'TOTAL_HRS': totals
}];
if (item > 1) {
doc.after(rows);
}
//console.log(rows);
//doc.createdCell: function (cell, data) { }
doc.autoTable(columns, rows);
doc.text(20, 20, fname + " " + lname + "'s " + 'Timesheet!');
//doc.text(20, 30, 'Organization Email: ' + username);
doc.save("Test.pdf");
} //end of timesheet function
timesheet(startd, endd, totals);
}); //end of object map
}); //end of post
我的问题是如何阻止jspdf为每次输入生成一个新文档?