1

I am making a Treasure Hunt app which has a scoreboard. In the scoreboard route I am asynchronously calling a function which return JSON data from MongoDB. This is what the function returns:

[
  {
    "_id": "rational",
    "total": 0
  },
  {
    "_id": "creative",
    "total": 0
  },
  {
    "_id": "confident",
    "total": 60
  },
  {
    "_id": "passionate",
    "total": 30
  },
  {
    "_id": "ingenious",
    "total": 30
  }
]

The _id is the team name and total is the number of points the team scored. I am using Handlebars as my templating engine and am still new to it. I want to make a HTML table that shows the team names with respective total scores but can't seem to figure it out. Please help me solve this problem.

1 Answer 1

3

To be honest, you could have solved this by reading the fine manual, but here's an example:

<table>
  {{#each teams}}
  <tr>
    <td>{{_id}}</td>
    <td>{{total}}</td>
  </tr>
  {{/each}}
</table>

In your handler, you render the template similar to this:

res.render('teams.hbs', { teams : [ LIST OF TEAMS ] });
Sign up to request clarification or add additional context in comments.

1 Comment

Shortly after posting this question I found the solution but thanks for the answer. It might help other people.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.