Currently, I am attempting to retrieve data from a REST API call and display it as a list using Handlebars, which functions as my view engine in a Node Express App.
Below is the route I am using:
router.get('api/projects', function(req, res){
Project.find(function(err, projects){
if(err)
res.send(err);
console.log(projects);
res.render('list-view', projects);
});
});
The JSON array "projects" contains various projects with keys for Name and _id.
Here is the HTML code in list-view.hbs:
{{#each .}}
<div class="thumbnail">
<div class="caption">
<h5> Name: {{name}} </h5>
</div>
</div>
{{/each}}
My issue lies in the fact that even though my list-view page correctly displays the projects in a list format as intended, it always shows a few empty projects at the end of the list. I am perplexed as to why this is happening. For instance, if I have 8 projects in the "projects" array, my page will render all 8 correctly but display 11 in total due to the extra empty projects. Despite confirming that there are only 8 projects in the array using console.log(projects), the extras persist. Any insights into why this is occurring?