I am getting issue to render my data to the html using 'ejs' template engine. Any one can help me please..?
When user goes to app.get('/', userList.list);
I am calling the function:
exports.list = function(req, res, next){
dataList.find({}, function(error, users){ // users consoles correctly.
var locals = {};
if(error) return next(error);
res.render('index', // this is file name. is it wrong?
{ name:name,
dept:dept
}
);
});
};
here is my index.ejs:
<body>
<h1>Please Add your Details</h1>
<% users.forEach(function(user) { %>
<div class="photo">
<h2><%=user.name%></h2>
<p>Department Is : <%= user.dept %></p>
</div>
<% }) %>
</body>
But nothing rendering in the page. what is wrong? any one help me. I am a beginner for this 'ejs' template and node.
Thanks for all,
It works for me:
exports.list = function(req, res, next){
dataList.find({}, function(error, users){
var locals = {};
if(error) return next(error);
res.render('index',{users:users,title:'how to render?'});
});
};
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다