首页 > 解决方案 > 如何在pdfmake中动态创建列表

问题描述

我正在尝试在角度应用程序中使用pdfmake创建 pdf 中的问答列表。我按以下模式设置问答部分:

{

text: 
    this.questionService.questions.
    Questions['sub-section'] 
    [0].questions[0].details['question-alt- 
    description'] + '\n', bold: true 
        },
      {
          style: 'tableExample',
          table: {
            style: 'table1',
            widths: ['*'],
            body: [
   [{ text :
    this.questionService.qanda.find(x => x.ActId == 647).ActVal == '' ? '\n' 
     : this.questionService.qanda.find(x => x.ActId == 647).ActVal === "No" ? 
      'Function for dependent question' : 'This should not print the 
        dependent question' ,
     }]
            ]
          }
      },

现在,情况是,如果我为上述问题选择否,则应该出现一个从属问题,否则它不应该出现。我尝试过的如下:

function builddependentquestion_1(data, columns) {
   const body = [];
   body.push([{
   text : 'The question i want to print',
   rowSpan: 1,
   fillColor: '#ffffff',
   bold: true,
   border: [false, false, false, false]}
   ]);

        return body;
  }

  function tabledependentquestion_1(data, columns) {
    return {
        table: {
            body: builddependentquestion_1(data, columns)
        }
    };
  }

我正在使用上述三元运算符中的函数,但它失败了。任何人都可以帮助解决这个问题。提前致谢。

标签: angularpdf-generationfrontendpdfmake

解决方案


推荐阅读