gpt4 book ai didi

javascript - 在 jsPdf AutoTable 中尝试动态数据时遇到问题

转载 作者:行者123 更新时间:2023-12-03 06:28:03 25 4
gpt4 key购买 nike

我尝试使用 jsPdf AutoTable 将动态数据打印到 PDF 中。但我未能做到这一点。我搜索了很多网站,但没有人提到将动态数据放入 Row 中。所以我的问题是,有没有什么方法可以将动态数据放入表行中,如果可以的话,请有人澄清我。注意:[这里没有使用HTML将数据存储到Pdf中,我直接从js获取数据]。

this.print=function(){
{

var mainData =this.printData(); // Here am getting Full Json data Here
var steps = mainData.steps; // From that data am Separating what i need
var criticality = mainData.criticality;
var categories = mainData.categories;
var checkup = mainData.checkup;

// 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, {
theme: 'striped', // 'striped', 'grid' or 'plain'
styles: {
overflow: 'linebreak',
columnWidth: 'wrap'
},
beforePageContent: function(data) {
doc.text("Process Name :"+mainData.name, 40, 30);
},
columnStyles: {
1: {columnWidth: 'auto'}
}
});

doc.save(mainData.name+ pdfsize +".pdf");
}



};

最佳答案

您需要替换它:

var rows = [
[processDescription,processes,NoOfSubProcess,subProcesses,categories,criticality]
];

像这样:

var rows = [];
for (var k = 0 ; k < processes.length; k++) {
rows.push([
processDescription,
processes[k],
NoOfSubProcess,
subProcesses[k],
categories[k],
criticality[k]
]);
};

rows 参数应该是数组的数组。如果我理解正确的话,你放在那里的基本上是一个数组的数组。

关于javascript - 在 jsPdf AutoTable 中尝试动态数据时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38561121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com