JsPDF子阵列数据推送

时间:2018-05-16 14:20:32

标签: javascript jspdf jspdf-autotable

我正在使用Jspdf和Jspdf-autotable在我的项目中生成PDF。但我无法弄清楚如何在行中推送子数组值。以下是JSON-

的示例
[{
            "voucherId":"18010110004",
            "date":"2018-01-01",
            "refNo":"0",
            "narration":null,
            "inWordTk":"Three Thousand  Taka  Only",
            "detailsList":[  
               {  
                  "ledgerName":"Cash",
                  "drAmount":3000,
                  "crAmount":0
               },
               {  
                  "ledgerName":"New Admission Fee Collection",
                  "drAmount":0,
                  "crAmount":3000
               }
            ]
          }
        ]

我想要它被喜欢这张照片 JsPdf

感谢。

1 个答案:

答案 0 :(得分:1)

您只需先取出该数据。在您的情况下是这样的:

var header = ['Ledger', 'Debit', 'Credit']
var data = objects.map(obj => Object.values(obj.detailList))
doc.autoTable(header, data)