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 6062255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:01:50+00:00 2026-05-23T09:01:50+00:00

Ok this is a little like inception for json objects and jquery templating… I

  • 0

Ok this is a little like inception for json objects and jquery templating… I want to know how to go deeper. The problem is that i am lazy and want the code to do the work for me….

Q:> How do you call a jQuery template recursively.

Take this json object:

var Links =
[{"Name":"Home","NiceUrl":"/home/","Children":null},
 {"Name":"MX-8","NiceUrl":"/mx-8/","Children":null},
 {"Name":"Quiz","NiceUrl":"/quiz/","Children":
      [{"Name":"Thank you","NiceUrl":"/quiz/thank-you/","Children":
         [{"Name":"Can't get here","NiceUrl":"/URL/","Children":null}]
     }]
 }];

I can easily get to “Quiz” and its child “Thankyou” using the following template:

<script id="itemTemplate" type="text/x-jquery-tmpl">
    <li><a href="${NiceUrl}">${Name}</a>
        {{tmpl($data) "#childTemplate"}}
    </li>
</script>
<script id="childTemplate" type="text/html">
    <ul>{{each Children}}<li><a href="${NiceUrl}">${Name}</a></li>{{/each}}</ul>
</script>

also used is the html and the call to replace it:

<script type="text/javascript">
    $("#itemTemplate").tmpl(Links).appendTo("#SiteMapHolder");
</script>
<ul id="SiteMapHolder">
    <%--jQuery Template will replace this empty space--%>
</ul>

I have tried setting the type of the second template to “text/x-jquery-tmpl” and calling a 3rd template but the data being passed seems to be the same as the parent that is calling it.

so to all beings of higher intelligence and experience then i, show me the way to be lazy and call a jQuery template recursively?

PS:sorry this is not in jsFiddle. it doesn’t like my script tags. 🙁

  • 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-05-23T09:01:50+00:00Added an answer on May 23, 2026 at 9:01 am

    I think you just need to check if Children exists and make a recursive call to the same item template with the Children as the data. You would conditionally also add the ul tag. See this jsfiddle for what I mean: http://jsfiddle.net/bernardchen1/SK2c6/.

    The template itself that I used looks like this:

    <script id="itemTemplate" type="text/x-jquery-tmpl">
    <li><a href="${NiceUrl}">${Name}</a>
        {{if Children}}
        <ul>
        {{tmpl(Children) "#itemTemplate"}}
        </ul>
        {{/if}}
    </li>
    

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

Sidebar

Related Questions

I have a repeater of div's that look a little bit like this: <div
I would like a little confirmation that I'm doing this correctly. Using rails single
In our application we have a little query that looks like this: var selectedAgents
first I want to say that I hope this doesn't look like I am
So I have an XML file that looks a little like this <xml> <post>
Using series.add(180, 1); produces a perfectly valid chart like this (little red dot at
This might sound like a little bit of a crazy question, but how can
I realize something like this has been asked, but this may be a little
I'm writing code like this, doing a little quick and dirty timing: var sw
I am a little confused here. I would like to do something like this:

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.