Home » Javascript » How to pass multiple arrays from node controller to handlebars?

How to pass multiple arrays from node controller to handlebars?

Posted by: admin November 1, 2017 Leave a comment

Questions:

I am trying to pass arrays to Handlebars template. Adding in rows and repeating looks fine. But I need to add to the columns, or each array element in column wise. Please to help.
Here’s my JS and HBS codes.
my table will looke like this https://drive.google.com/file/d/0B14_9O4t0ffPa0lYMENYSzg5bG8/view?usp=sharing

router.get('/students_list', function(req, res){
	var arr;
	User.find({},(err, docs) => {
		// arr = docs.map(ob=> ob.name);
		// arr = docs[6]
		console.log(docs);
		var names = docs.map(ob=> ob.name);
		var age = docs.map(ob=> ob.age);
		var clas = docs.map(ob=> ob.clas);
		var ad_date =  docs.map(ob=> ob.ad_date);
		var mob_num = docs.map(ob=> mob_num);
		var email = docs.map(ob => ob.email);
		res.render('student-list', {con:{names, age, clas, ad_date, mob_num, email}}
	);
	});
});
  <thead>
                        <tr>
                          <th>Name</th>
                          <th>Class</th>
                          <th>Age</th>
                          <th>Admit date</th>
                          <th>Mob. Number</th>
                          <th>E-mail ID</th>
                        </tr>
                      </thead>


                      <tbody>
                         {{#each names}}
                        <tr>
                           
                          <td>{{this}}</td>
                        </tr>
                        {{/each}}
Answers: