我試圖使用jsPdf AutoTable將動態數據打印到PDF中,但是我沒有這麼做。我在很多網站搜索過,但沒有人說過關於動態數據的問題。所以在這裏我的問題是,是否有任何方法可以讓動態數據進入表格行,如果有人能澄清我的話。注意:[這裏沒有使用HTML將數據存儲到PDF中,我直接從js獲取數據]。在jsPdf AutoTable中嘗試動態數據時遇到問題
this.print=function(){
\t {
\t \t
\t \t var mainData =this.printData(); // Here am getting Full Json data Here
\t \t var steps = mainData.steps; // From that data am Separating what i need
\t \t var criticality = mainData.criticality;
\t \t var categories = mainData.categories;
\t \t var checkup = mainData.checkup;
\t \t
// This is For to Take the Steps Data alone
$scope.getSteps = function(steps) {
var data = [];
for (var i = steps.length; i-- > 0;) {
data.push(steps[i].name+"\n"+"\n");
}
return data;
}
// Like wise am getting every single object data's
$scope.getNumbersOfSubSteps = function(steps) {
var data = 0;
for (var i = 0 ; i < steps.length; i++) {
for (var j = 0; j<steps[i].steps.length; j++) {
}
data = j ;
}
return data;
}
// this is for Sub Proceeses
$scope.getSubProcesses = function(steps) {
var data = [];
for (var i = 0 ; i < steps.length; i++) {
for (var j = 0; j<steps[i].steps.length; j++) {
data.push(steps[i].steps[j].name+"\n");
}
}
return data;
}
$scope.getCategories = function(categories) {
var data = [];
for (var i = categories.length; i-- > 0;) {
data.push(categories[i].name+"\n");
}
return data;
}
$scope.getCriticality = function(criticality) {
var data = [];
for (var i = criticality.length; i-- > 0;) {
data.push(criticality[i].name+"\n");
}
return data;
}
// Pdf Print Function Begins
var columns = ["ProcessDescription", "Steps", "#ofSubProcesses", "SubSteps","Category","Criticality","CheckUp"];
var processDescription =mainData.description;
var processes= $scope.getSteps(steps);
var NoOfSubProcess = $scope.getNumbersOfSubSteps(steps);
var subProcesses = $scope.getSubProcesses(steps);
console.log('Subprocsses length',subProcesses);
var categories = $scope.getCategories(categories);
var criticality = $scope.getCriticality(criticality);
// The Problem Begins here , Am struggling to Get the Separate data's here !
var rows = [
[processDescription,processes,NoOfSubProcess,subProcesses,categories,criticality]
];
var pdfsize='a1';
var doc = new jsPDF('p', 'pt',pdfsize);
doc.autoTable(columns, rows, {
\t theme: 'striped', // 'striped', 'grid' or 'plain'
\t styles: {
\t overflow: 'linebreak',
\t columnWidth: 'wrap'
\t },
\t beforePageContent: function(data) {
\t doc.text("Process Name :"+mainData.name, 40, 30);
\t },
columnStyles: {
1: {columnWidth: 'auto'}
}
});
doc.save(mainData.name+ pdfsize +".pdf");
}
\t
\t
};
你是什麼意思的動態數據?在調用autotable之前,你可以用循環構造行對象嗎? –
動態數據的意思是,var進程= $ scope.getSteps(steps); - >這個過程有三個進程,所以如果我使用Process進入該行,它會在同一單元格中打印三個數據, –
您必須將進程轉換爲與自動選項匹配的格式。如果您查看repo有一個examples/examples.js文件,如果你需要指針,它使用動態數據。 –