我正在努力解决这个问题,我相信它并不复杂。出于某种原因,我从这段代码中得到了以下错误:
/*
* 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
从渲染调用中删除变量,视图渲染得很好。
有任何想法吗?
谢谢,
路易斯