首页 > 解决方案 > 我可以在 jsPDF-autotable 正文中放置 for 循环吗?

问题描述

我在填充 jsPDF-autotable 正文时遇到了麻烦。我可以循环这样的东西吗?

 doc.autoTable({ 
                    head: [this.pdf_head],
                    body: [
                            for(let i = 0; i < this.generated_table.length; i++)
                            {
                                for(let j = 0; j < this.generated_column.length; j++)
                                {
                                    [this.pdf_body[i][j]];
                                }
                            }
                        ],
               })

我正在使用 vs-table 所以我不能使用 html 格式。此代码当前无法正常工作,但有没有办法做到这一点?谢谢!

标签: javascriptjspdfjspdf-autotable

解决方案


let bodyData = [];
for(let i = 0; i < this.generated_table.length; i++)
{
  let rowData = [];
  for(let j = 0; j < this.generated_column.length; j++)
  {
    rowData.push(this.pdf_body[i][j]);
  }
  bodyData.push(rowData);
}

doc.autoTable({ 
    head: [this.pdf_head],
    body: bodyData
})

你可以写这样的代码。


推荐阅读