问题
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