My project code has been working perfectly fine 5 months ago. Now I am not getting why handlebars is not showing data in any list. I have checked backend, where I am getting array of categories and i can console.log elements of objects inside the array. Here is my backend code:
// shows category list
exports.categoryList = async( req, res )=> {
var category = await Cat.find()
var count = 1
category.map( doc=> doc.count = count++ )
console.log(category)
console.log(category[0].name)
res.render('parents/categoryList', { category })
}
Output of these console.log:
[ { subCategories: [],
brands: [],
enabled: false,
discount: null,
_id: 5e6f2a069894412b749e2fca,
name: 'abcd',
created: 2020-03-16T07:25:58.335Z,
__v: 0 } ]
abcd
In handlebar I have tried printing category variable which I have passed from backend:
<p>{{category}}</p>
{{#each category}}
count: {{this.count}} <br>
id: {{this._id}}<br>
{{/each}}
Front-end output:
{ subCategories: [], brands: [], enabled: false, discount: null, _id: 5e6f2a069894412b749e2fca, name: 'abcd', created: 2020-03-16T07:25:58.335Z, __v: 0 }
count: 1
id:
As you can see the count variable what I have set in the backend code is not inside the category object but its printing while iterating through the category array. Could anyone tell me what's went wrong?