Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9300487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:47:29+00:00 2026-06-18T22:47:29+00:00

I have a JSON structure similar as below. markers: { Lifestyle : [ {Name1

  • 0

I have a JSON structure similar as below.

"markers": {
   "Lifestyle" : [
      {"Name1" : "Something"},
      {"Name2" : "Something"}
   ],  
   "Transport" : [
      {"Name1" : "Something"},
      {"Name2" : "Something"}
   ]

I want to create a menu with nested list-item using the above JSON.

<ul id="menu">
   <li class="Lifestyle">Lifestyle
      <ul class="sub-cat">
         <li>Something</li>
         <li>Something</li>
      </ul>
   </li>
   <li class="Transport">Transport
      <ul class="sub-cat">
         <li>Something</li>
         <li>Something</li>
      </ul>
   </li>
</ul>

I have tried adding a helper function to extract the name of the properties but i’m not sure how to add the sub-categories. Any advise is appreciated.

Edit: Added code

Handlebars.registerHelper('getCategory',function(object) {
                var categories = [];
                for(var x in object) {
                    categories.push(x);
                }
                console.log(categories);
                return categories;
            });

This just returns the category names. I know i can return HTML using the same helper but i’m not sure how i would add the nested structure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T22:47:30+00:00Added an answer on June 18, 2026 at 10:47 pm

    In your case, the helper would be an iterator1 converting an object to a list of (key, value) pairs. NOte that an helper has to return HTML:

    // context : object you wish to transform
    // options.fn will contain the HTML block
    Handlebars.registerHelper('pairs', function(context, options) {
        var cells = [], html, k;
        for (k in context) {
            if (context.hasOwnProperty(k)) {
                html = options.fn({
                    key: k,
                    value: context[k]
                }); 
                cells.push(html);
            }
        }
        return cells.join('');
    });
    

    And your template could look like this

    <ul id="menu">
       {{#pairs .}}
       <li class="{{key}}">{{key}}
          <ul class="sub-cat">
          {{#each value}}
          {{#pairs .}}
              <li>{{key}}: {{value}}</li>
          {{/pairs}}
          {{/each}}
          </ul>
       </li>
        {{/pairs}}
    </ul>
    

    The nested level has to go through an each helper before being converted to a pair since the underlying data in an array.

    Finally, a Fiddle http://jsfiddle.net/hnrQC/ to see this code in action.

    1 See Block helpers in Handlebars: simple iterators

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON-like data structure (which I don't want to change) that is
I have folder structure and I would like to create JSON objects based on
I have some data and need to create a json file with this structure
Possible Duplicate: I have a nested data structure / JSON, how can I access
I want to pass a JSON data structure to an MVC (3) Controller, have
Possible Duplicate: I have a nested data structure / JSON, how can I access
I have a structure similar to the following: /root/ /root/data/ /root/data/script.php /root/data/some.json /root/data/feature/one.json /root/data/feature/two.json
I have a json nested object, similar to this . In my case, I
I have a JSON data structure as shown below: { name: World, children: [
I have a json structure that looks something like this: list:[ { type:link, href:http://google.com

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.