【问题标题】:PDFMAKE: How to Repeat Array[ ] Items in 'content'PDFMAKE:如何在“内容”中重复数组 [] 项目
【发布时间】:2017-09-27 18:55:08
【问题描述】:

我有一个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],
            ]
   }

它是否提供了一个简单的方式,比如*ngForngRepeat in PDFMake 或其他方式,比如for(i=0; i<array.length; i++)

【问题讨论】:

    标签: javascript html angularjs arrays pdfmake


    【解决方案1】:

    您可以在文档定义中使用 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。

    【讨论】:

    • 太棒了! @arnaud 德尔。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-21
    • 2021-10-17
    • 1970-01-01
    • 2015-07-20
    • 1970-01-01
    • 1970-01-01
    • 2023-02-11
    相关资源
    最近更新 更多