1

I am trying to access an inner object from JSON using Handlebars.js. I tried but I am not getting the address object have the area value.

Here is my HTML:

<table class="table table-striped">
  <thead>
    <tr>
      <th>Firstname</th>
      <th>Lastname</th>
      <th>Email</th>
      <td>Address</td>
    </tr>
  </thead>
  <tbody>   
    {{#empdetails}}
    <tr> 
      <td>{{firstname}}</td>
      <td>{{lastname}}</td>
      <td>{{email}}</td>
      {{#each addres}}
      <td>{{addres.area}}</td>
      {{#each}}
    </tr>
  {{/empdetails}}
  </tbody>
</table>

And here is my JavaScript:

var data = {empdetails: [
  {firstname: "Success", lastname: "Doe", email: "[email protected]",addres:[{area:"mtm"}]},
   {firstname: "Danger", lastname: "Moe", email: "[email protected]",addres:[{area:"vij"}]},
  {firstname: "ravi", lastname: "m", email: "[email protected]",addres:[{area:"chennai"}]},
  {firstname: "sandeep", lastname: "sand", email: "[email protected]",addres:[{area:"mumbai"}]},
  {firstname: "kishore", lastname: "kis", email: "[email protected]",addres:[{area:"delhi"}]},
  {firstname: "vivek", lastname: "ve", email: "[email protected]",addres:[{area:"vijag"}]},
  {firstname: "adi", lastname: "udathu", email: "[email protected]",addres:[{area:"guntur"}]},
  {firstname: "prem", lastname: "muk", email: "[email protected]",addres:[{area:"nellore"}]},
  {firstname: "ramesh", lastname: "Doe", email: "[email protected]",addres:[{area:"mtm"}]},
  {firstname: "naresh", lastname: "muk", email: "[email protected]",addres:[{area:"rajamandri"}]}
]};

Kindly help me to get the address->area value.

1 Answer 1

1

Use {{this.area}}. this inside an each block corresponds to the item at the current index in the loop.

Under the "The each block helper" section

Inside the block, you can use this to reference the element being iterated over.

Sign up to request clarification or add additional context in comments.

Comments

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.