PDFMAKE: How to Repeat Array[ ] Items in 'content'

孤街醉人 提交于 2020-01-14 06:08:29

问题


I have an Array within Items. I want to repeat them in a Table like this in PDFMake.

table: {
      multiple pages
      headerRows: 2,
      widths: ['auto', 100, 200, 'auto', 'auto', 'auto'],

      body: [
        ['Nr.', 'Name', 'Beschreibung', 'Preis', 'Anzahl', 'MwSt(%)'],
        [bill.billItems[i].itemNumber, bill.billItems[i].name, bill.billItems[i].description, bill.billItems[i].price, bill.billItems[i].quantity, bill.billItems[i].vat],
            ]
   }

Does it give a simple way like *ngFor or ngRepeat in PDFMake or an other way like for(i=0; i<array.length; i++)


回答1:


You can use javascript variables in your docdefinition. Try with the following :

// playground requires you to assign document definition to a variable called dd

var rows = [];
rows.push(['Nr.', 'Name', 'Beschreibung', 'Preis', 'Anzahl', 'MwSt(%)']);

for(var i of [1,2,3,4]) {
    rows.push(['#.'+i, 'xx', 'xx', 'xx', 'xx', 'xx']);
}

var dd = {
    content: {
        table: {
                widths: ['*', 100, 200, '*', '*', '*'],
                body: rows
            }
    }

}

You can directly copy/paste this code in the pdfmake playground to see the live rendered PDF.



来源:https://stackoverflow.com/questions/43700804/pdfmake-how-to-repeat-array-items-in-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!