PDFMAKE:如何重复Array []'content'中的项目 [英] PDFMAKE: How to Repeat Array[ ] Items in 'content'

查看:181
本文介绍了PDFMAKE:如何重复Array []'content'中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Items 中有一个数组。我想在 PDFMake 这样的表格中重复它们。

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],
            ]
   }

它是否提供了像 * ngFor ngRepeat PDFMake 或其他方式如 for(i = 0; i

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

推荐答案

您可以在您的docdefinition中使用javascript变量。
请尝试以下操作:

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
            }
    }

}

您可以直接将此代码复制/粘贴到 pdfmake游乐场查看现场呈现的PDF。

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

这篇关于PDFMAKE:如何重复Array []'content'中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆