【问题标题】:why is my pdf table printing just one element out of the for loop为什么我的 pdf 表格只打印 for 循环中的一个元素
【发布时间】:2023-01-17 23:32:14
【问题描述】:
``

生成PDF(){

this.attendList =this.attendanceList;



for(let i:number=0;i<this.attendList.length; i++){

每当我生成 pdf 表时,只有第一个元素只显示数组的第一个元素,有人可以帮我吗


let bod:any[] = [


           [
           
            this.attendList[i].id, this.attendList[i].name, this.attendList[i]

           .status,this.attendList[i].created_date
           ]
      
]
         
          
     this.bodList=bod;
     console.log(this.bodList)
     }



  let text = "";
 




  var pdf = new jsPDF();

  pdf.setFontSize(2);
  pdf.text('Attendace List', 11, 8);
  pdf.setFontSize(12);
  pdf.setTextColor(99);


  (pdf as any).autoTable({
  head: this.header,
  body: this.bodList,
  theme: 'grid',
  didDrawCell: data => {
      // console.log(data.column.index)
  }
  })

  // Open PDF document in browser's new tab
  pdf.output('dataurlnewwindow')

  // Download PDF doc  
  // pdf.save('table.pdf');


  
}  

`
```

【问题讨论】:

    标签: angular typescript


    【解决方案1】:

    您在每个循环中都完全设置了 bodlist,而不是将新项目推入其中。

    [1] -> [2] -> [66]

    代替

    [1] -> [1, 2] -> [1, 2, 66]

    你要:

    let bod:any[] = [       
        this.attendList[i].id, 
        this.attendList[i].name, 
        this.attendList[i].status,
        this.attendList[i].created_date
          
    ];
    
    this.bodList.push(bod);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 2022-01-13
      • 2022-08-23
      • 1970-01-01
      • 2019-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多