我正在與pdfmake一起使用javascript生成pdf。我試圖動態地而不是建一個表的作品,這是我嘗試用PDF動態建立表格模板
$.ajax({
type: "POST",
url: myURL,
success:function(data){
/* data has a format like :
*[{"peaje":"Peaje 1","ruta":"Ruta 1","fechaCruce":"2014-10-18","hora":"15:42","valor":"5000"},{"peaje":"Peaje 1","ruta":"Ruta 1","fechaCruce":"2014-10-18","hora":"14:21","valor":"7000"},{"peaje":"Peaje 1","ruta":"Ruta 1","fechaCruce":"2014-09-19","hora":"11:58","valor":"17000"}]
*/
var peajes = JSON.parse(data);
var body = [];
var titulos = new Array('PEAJE', 'RUTA', 'FECHA CRUCE', 'HORA', 'VALOR');
body.push(titulos);
for (key in peajes)
{
if (peajes.hasOwnProperty(key))
{
var peaje = peajes[key];
var fila = new Array();
fila.push(peaje.peaje.toString());
fila.push(peaje.ruta.toString() );
fila.push(peaje.fechaCruce.toString());
fila.push(peaje.hora.toString() );
fila.push(peaje.valor.toString());
body.push(fila);
}
}
console.log(body);
var docDefinition = {
content: [
{
table: {
headerRows: 1,
widths: [ '*', 'auto', 100, '*' ],
body: body
}
}]
};//end docDefinition
pdfMake.createPdf(docDefinition).open();
}//end success
});
這是庫http://pdfmake.org/#/gettingstarted
我不知道我做錯了的例子嗎?