2016-08-01 15 views
0

jsPdfオートテーブルを使用して動的データをpdfファイルに出力しようとしています。エラーが私のコードであれば私ができるのを意味する:これをやっているとき、私はここでjsPdfオートテーブルの未知の型エラー

The data should be an object or array, is: function  (jspdf.plugin.autotable.js:10) 

TypeError: t.forEach is not a function  (angular.js:12314) 

  var getColumns = function() { 
 
       \t  return [ 
 
       \t   {title: "ID", dataKey: "id"}, 
 
       \t   {title: "Name", dataKey: "first_name"}, 
 
       \t   {title: "Email", dataKey: "email"}, 
 
       \t   {title: "City", dataKey: "city"}, 
 
       \t   {title: "Country", dataKey: "country"}, 
 
       \t   {title: "Expenses", dataKey: "expenses"} 
 
       \t  ]; 
 
       \t }; 
 
       \t function getData(mainSteps) { 
 
       \t  mainSteps = mainSteps || 4; 
 
       \t  //var sentence = faker.lorem.words(12); 
 
       \t  var data = []; 
 
       \t  for (var j = 1; j <= rowCount; j++) { 
 
       \t   data.push({ 
 
       \t    id: j, 
 
       \t    first_name: this.getSteps(), 
 
       \t    email: this.getSteps(), 
 
       \t    country: this.getSteps(), 
 
       \t    city: this.getSteps()(), 
 
       \t    expenses: this.getSteps() 
 
       \t   // text: shuffleSentence(sentence), 
 
       \t    //text2: shuffleSentence(sentence) 
 
       \t   }); 
 
       \t  } 
 
       \t  return data; 
 
       \t } 
 
       var pdfsize='a4'; 
 
       var doc = new jsPDF('p', 'pt',pdfsize); 
 
     
 
       doc.autoTable(getColumns, getData, { 
 
       \t theme: 'grid', // 'striped', 'grid' or 'plain' 
 
       \t headerStyles: { 
 
         fillColor: [12, 234, 227], 
 
         textColor: [12, 1, 1] 
 
        }, 
 
        // margin: { top: 50, left: 20, right: 20, bottom: 0 }, 
 
       \t styles: { 
 
       \t  overflow: 'linebreak', 
 
       \t  columnWidth: 88 
 
       \t  }, 
 
       \t  beforePageContent: function(data) { 
 
       \t  \t 
 
       \t   doc.text("Process Name :"+mainData.name+" || "+"Description :"+mainData.description, 40, 30); 
 
       \t   
 
       \t  }, 
 
       \t  //startY: doc.autoTableEndPosY() + 20, 
 
        columnStyles: { 
 
         0: {columnWidth: 200} 
 
        } 
 
        }); 
 
       //startY: doc.autoTableEndPosY() + 20 
 
        doc.save(mainData.name+".pdf"); 
 
      } 
 
     };
は注意、私のコードです The headers should be an object or array, is: function (jspdf.plugin.autotable.js:10)

のようなエラーのいくつかの種類を持ってその解決策を見つけてください。しかし、エラーは(jspdf.plugin.autotable.js:10)と(angular.js:12314)にあるので、ここで混乱しています。誰かが私plsを明確にすることはできますか?

答えて

2

エラーが説明するように、入力データは配列またはオブジェクトでなければなりません。あなたの場合、単に関数を呼び出し可能にする代わりに関数を呼び出すことを意味します。この

doc.autoTable(getColumns, getData, {...});

はい、あなたは正しいです

doc.autoTable(getColumns(), getData(), {...});

+1

とを交換してください。それは私の "不注意な"ミスでした:( –

+0

、こんにちは..私は1つの小さな疑いがあります。私はカスタム幅の列を適用しようとしているので、あなたのgithubサイトであなたの指示に従った。私のコードを助けてくれますか?私のコードは - > {title: "Category"、dataKey: "cate"、width:20}、 –

+0

ですか、それ以外の方法がありますか? –

関連する問題