当我想从我的jade模板生成带有jade-pdf-redline的PDF时,我有这样的错误:
TypeError: Cannot read property 'length' of undefined on line 12
at eval (eval at <anonymous> (/var/www/html/BP_webApp/node_modules/jade-pdf-redline/node_modules/jade/lib/jade.js:160:8), <anonymous>:62:26)
at res (/var/www/html/BP_webApp/node_modules/jade-pdf-redline/node_modules/jade/lib/jade.js:161:38)
at Stream.end (/var/www/html/BP_webApp/node_modules/jade-pdf-redline/lib/index.js:31:18)
at _end (/var/www/html/BP_webApp/node_modules/jade-pdf-redline/node_modules/through/index.js:65:9)
at Stream.stream.end (/var/www/html/BP_webApp/node_modules/jade-pdf-redline/node_modules/through/index.js:74:5)
at Stream.onend (stream.js:59:10)
at emitNone (events.js:85:20)
at Stream.emit (events.js:179:7)
at drain (/var/www/html/BP_webApp/node_modules/jade-pdf-redline/node_modules/through/index.js:34:23)
at Stream.stream.queue.stream.push (/var/www/html/BP_webApp/node_modules/jade-pdf-redline/node_modules/through/index.js:45:5)
at Stream.end (/var/www/html/BP_webApp/node_modules/jade-pdf-redline/node_modules/through/index.js:15:35)
at _end (/var/www/html/BP_webApp/node_modules/jade-pdf-redline/node_modules/through/index.js:65:9)
at Stream.stream.end (/var/www/html/BP_webApp/node_modules/jade-pdf-redline/node_modules/through/index.js:74:5)
at Stream.method [as end] (/var/www/html/BP_webApp/node_modules/jade-pdf-redline/node_modules/duplexer/index.js:47:39)
at ReadStream.onend (_stream_readable.js:491:10)
at ReadStream.g (events.js:273:16)
at emitNone (events.js:85:20)
at ReadStream.emit (events.js:179:7)
at endReadableNT (_stream_readable.js:906:12)
at nextTickCallbackWith2Args (node.js:475:9)
at process._tickCallback (node.js:389:17)
index.js
conn.query("SELECT * FROM tblForm", function(err, rows) {
if (err) {
console.log('Error selecting: %s', err);
}
for (var i in rows) {
console.log('Post: ', rows[i]);
}
res.render('form', {
title: 'titlw',
rows: rows
});
fs.createReadStream('views/form.jade').pipe(jadepdf()).pipe(fs.createWriteStream('form.pdf'));
});
form.jade
- for(var i = 0, len = rows.length; i < len; i++) {
div
label Programme
input(style='float: right; clear: both; width: 300px;' value='#{rows[i].programme}')
div
br
label Action Type
input(style='float: right; clear: both; width: 300px;' value='#{rows[i].actionType}')
div
br
label Call
input(style='float: right; clear: both; width: 300px;' value='#{rows[i].callCell}')
div
br
label Language
input(style='float: right; clear: both; width: 300px;' value='#{rows[i].lang}')
- }
该API无法读取此行 - for(var i = 0,len = rows.length; i&lt; len; i ++){。你有什么建议吗?
答案 0 :(得分:0)
我认为,您应该在rows
函数中传递jadepdf()
变量。
var options = {
"locals": {
"rows": rows
}
};
fs.createReadStream('views/form.jade').pipe(jadepdf(options)).pipe(fs.createWriteStream('form.pdf'));
因为,当jadepdf
尝试将其转换为.pdf
时,jade模板的空值为rows
。