Как исправить: невозможно создать свойство 'header' для строки - PullRequest
0 голосов
/ 03 мая 2019

Я пытаюсь создать PDF, используя jspdf из данных json.Но это вызывает ошибку, которую я не могу понять.Пожалуйста, помогите мне решить проблему.

Данные:

fileDataSpecific = [{ Date: "01/Jan/2019",
    ServerName: "prlhpcms01",
    ServerRequest: "Front End License returned",
    ServerStatus: "57 timed out",
    Time: "01:03:32",
    UserName: "root",
    srno: 1 }]

displayColumns = [
    { "val": "srno", "col": "Sr. No." },
    { "val": "ServerName", "col": "Server Name" },
    { "val": "UserName", "col": "User Name" },
    { "val": "Date", "col": "Date" },
    { "val": "Time", "col": "Time" },
    { "val": "ServerRequest", "col": "Server Request" },
    { "val": "ServerStatus", "col": "Server Status" }];

Моя функция:

PrintData() {
    var pdfData = this.fileDataSpecific
    var pdfCol = this.displayedColumns
    var doc = new jsPDF()
    var col = [], row = []
    pdfCol.forEach(element => {
      col.push(element.col)
    });    
    pdfData.forEach(element => {
      var tempArray = []
      pdfCol.forEach(element1 => {
        tempArray.push(element[element1.val])
      });
      row.push(tempArray)
      tempArray = []
    });
    doc.autoTable(col, row);
    doc.save('Test.pdf');
  }

Ошибка:

enter image description here

Пожалуйста, помогите кому-нибудь!Спасибо.

1 Ответ

0 голосов
/ 03 мая 2019

Вам нужно обработать var pdfData = this.fileDataSpecific как массив var pdfData = [this.fileDataSpecific]

fileDataSpecific = { Date: "01/Jan/2019",
    ServerName: "prlhpcms01",
    ServerRequest: "Front End License returned",
    ServerStatus: "57 timed out",
    Time: "01:03:32",
    UserName: "root",
    srno: 1 }

let displayedColumns = [
    { "val": "srno", "col": "Sr. No." },
    { "val": "ServerName", "col": "Server Name" },
    { "val": "UserName", "col": "User Name" },
    { "val": "Date", "col": "Date" },
    { "val": "Time", "col": "Time" },
    { "val": "ServerRequest", "col": "Server Request" },
    { "val": "ServerStatus", "col": "Server Status" }];


function PrintData() {
    var pdfData = [fileDataSpecific]
    var pdfCol = displayedColumns
    //var doc = new jsPDF()
    var col = [], row = []
    pdfCol.forEach(element => {
      col.push(element.col)
    });    
    pdfData.forEach(element => {
      var tempArray = []
      pdfCol.forEach(element1 => {
        tempArray.push(element[element1.val])
      });
      row.push(tempArray)
      tempArray = []
    });
    console.log(row)
    //doc.autoTable(col, row);
    //doc.save('Test.pdf');
  }
  
  PrintData();
...