我有一个Array within Items
。我想在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],
]
}
它是否给出了像*ngFor
这样的简单方法或ngRepeat
在PDFMake
或其他方式如 for(i=0; i<array.length; i++)
最佳答案
您可以在文档定义中使用 JavaScript 变量。 尝试以下操作:
// 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
}
}
}
您可以直接将此代码复制/粘贴到pdfmake playground中查看实时渲染的 PDF。
关于javascript - PDFMAKE:如何重复 'content' 中的数组 [ ] 项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43700804/