我正在努力弄清楚這一點,我相信這並不複雜。對於一些reasonI從這個代碼得到的錯誤如下:expressjs查看變量
/*
* GET home page.
*/
exports.index = function(req, res){
exec('ls -l ~/Sites/branches | grep "^d"', function (error, stdout, stderr) {
// var lines = stdout.split("\n");
// var folder;
// lines.forEach(function(line){
// folder = line.match(/([^\s]+)$/igm);
// if (folder!='null') {
// sys.puts(folder);
// }
// });
res.render('index', {
title: 'Express',
lines: 'hi'
});
});
};
我註釋掉了,我打算從獲得的數據lines
的線條和簡單的設置lines
爲一個字符串。無論如何,它給了我下面的錯誤。
Express
500 ReferenceError: /Users/luisgomez/Desktop/mashlocaldevman/views/index.ejs:10 8| <h1><%= title %></h1> 9| <p>Welcome to <%= title %></p> >> 10| <p>Lines: <%= lines.length %></p> 11| </body> 12| </html> 13| lines is not defined
<%= title %>
Welcome to <%= title %>
Lines: <%= lines.length %>
lines is not defined
at eval (eval at (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/ejs/lib/ejs.js:226:12))
at exports.compile (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/ejs/lib/ejs.js:228:15)
at Object.exports.render (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/ejs/lib/ejs.js:266:13)
at View.exports.renderFile [as engine] (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/ejs/lib/ejs.js:292:22)
at View.render (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/express/lib/view.js:75:8)
at Function.app.render (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/express/lib/application.js:504:10)
at ServerResponse.res.render (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/express/lib/response.js:677:7)
at exports.index (/Users/luisgomez/Desktop/mashlocaldevman/routes/index.js:7:7)
at callbacks (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/express/lib/router/index.js:165:11)
at param (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/express/lib/router/index.js:139:11)
我對視圖和最新版本的express使用簡單的HTML。如果我從呈現調用中刪除'lines
變量,視圖呈現正常。
任何想法?
謝謝
路易斯
你們看透了這一點? – bryanmac