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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:24:52+00:00 2026-06-14T18:24:52+00:00

I am building a small page which calls an API using jquery’s getJSON and

  • 0

I am building a small page which calls an API using jquery’s getJSON and then renders the data using a mustache template (at least that’s the plan). However my JSON does not have a node root and am unable to loop through the JSONs response data using the proper mustache mechanics.

//start
file : jsonresponse.jsonp

?([{"CountryIsoAlpha3Code":"AFG","CountryName":"Afghanistan"},
{"CountryIsoAlpha3Code":"ALA","CountryName":"Åland Islands"},
{"CountryIsoAlpha3Code":"ALB","CountryName":"Albania"}])
//end

//start
file: tmpl.mustache

<option value="{{CountryIsoAlpha3Code}}">{{CountryName}}</option>
//end

//start
file: render.js

$.getJSON(jsonresponse.jsonp, function(data) { 
   var tpl = tmpl.mustache,
   i=data.length,
   html = '';
     while(i--){
       html = html + mustache.render(tpl, data[i]);
     }

//end

I realize this is completely wrong (in the template usage only, assume I am actually passing the data and template properly) but it does work. but what if I want to do the follow… HOW DO I DO IT!?:

//start
//file : daydreamer.mustache

<h1>This title is only awesome when it's rendered once</h1>
{{#}}  //no root node attempt at recursive templating rendering
     <option value="{{CountryIsoAlpha3Code}}">{{CountryName}}</option>
{{/}}

//end  

If this is unclear please let me know I know a poor question is an eye sore. I will try to edit as soon as possible. Thanks.

  • 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-14T18:24:54+00:00Added an answer on June 14, 2026 at 6:24 pm

    Depending on the pieces you control on this application/use case, you have 2 possible fixes: either modify the JSON data to include such root node, or add that root node to your data on your end.

    The mustache template will need to get modified as follows for both solutions:

    {{#options}}
        <option value="{{CountryIsoAlpha3Code}}">{{CountryName}}</option>
    {{/options}}
    

    Now you either wrap the data directly on the server or on your end, and then the getJSON call will be like this for the second solution (for the first one, replace the {options: data} wrapper with just data). I’m going with the second one assuming you can’t control the server side because that API is fixed/mandated by somebody else:

    $.getJSON("jsonresponse.jsonp", function(data) { 
        var tpl = tmpl.mustache,
            html = '';
    
        html = mustache.render(tpl, {options: data});
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a small-scale website (a personal one) in which each page would have
I'm building a small tabbed c# Form and I'd like each tab page to
We're building a small sub-site that, on the front page, has a one input
I´m building a small application with Jquery and PHP. Jquery (index.html) adds Form Fields
I'm building this small java applet in which I need a JPanel which will
I'm building small one page application with rails 3.1 mongodb and backbonejs. I have
I'm building a page which works fine in all browsers except IE6, where a
I'm building a web page form with jquery append() , html() etc and I'm
I'm building a small internal social media data sharing app. A bunch of users
I'm building a small system, which has nice htaccess rewritten urls. Now I'm wondering

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.