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

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

问题描述

我在Items中有一个 Array .我想在 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],
            ]
   }

它是否提供了简单的方法,例如 PDFMake 中的 * ngFor ngRepeat for(i = 0; i< array.length; 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++)

推荐答案

您可以在文档定义中使用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:如何在&amp;#39; content&amp;#39;中重复Array []项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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