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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:59:02+00:00 2026-06-02T06:59:02+00:00

I am new to Dust.js and am trying to iterate a JSON object with

  • 0

I am new to Dust.js and am trying to iterate a JSON object with records and render each of them into a row within a table. Below is the script, I am using to render the table, but am running into issues, I guess while rendering, especially the template argument of the render function. Appreciate if I could be pointed in the right direction

<div id="dustPlaceholder"></div>  
    <script id="goalTemplate">
        <table id="dustGoals">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Age</th>
                </tr>
            </thead>
            <tbody>
                {#friends}
                <tr>
                    <td>{name}</td>
                    <td>{age}</td>
                </tr>
                {/friends}
            </tbody>
        </table>
    </script> 
    </div>

     <script type="text/javascript">
         var src = document.getElementById("goalTemplate").innerHTML;
         var compiled = dust.compile(src);
         dust.render("goalTemplate", { friends: [ { name: "Moe", age:  37}]}, 
         function(err, out) {
          document.getElementById('dustPlaceholder').innerHTML = out;
        });   
     </script>
  • 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-02T06:59:03+00:00Added an answer on June 2, 2026 at 6:59 am

    You need to include the entire Dust.js library if you are going to be rendering on the client, so you need to include the dust-full-0.3.0.min.js. Additionally,

    <script src="dust-full-0.3.0.min.js"></script>
    

    Also, what is “goalTemplate”?

    Also what are you compiling? There are no variables in there. You need to compile the actual HTML – the content in the DIV tag. So everything including the div tags belong in the src variable.

    Also, you must assume a name to the compiled template so it can be accessed. I’m really confused what you were doing before, but this example should work:

    <script src="dust-full-0.3.0.min.js"></script>
    <script type = "text/javascript">
    var source = "<div id="dustPlaceholder"></div>  
        <script id="goalTemplate">
            <table id="dustGoals">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Age</th>
                    </tr>
                </thead>
                <tbody>
                    {#friends}
                    <tr>
                        <td>{name}</td>
                        <td>{age}</td>
                    </tr>
                    {/friends}
                </tbody>
            </table>
        </script> 
        </div>";
    
         var compiled = dust.compile(src, goalTemplate);
         dust.render("goalTemplate", { friends: [ { name: "Moe", age:  37}]}, 
         function(err, out) {
          document.getElementById('dustPlaceholder').innerHTML = out;
        }); 
         </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New programmer here, I am trying to understand and break down this code below
New to Subsonic 3.0 and wondering how to perform LIKE operators on object attributes.
New to all this so forgive my ignorance. I am trying to figure out
New to files in C, trying to read a file via fread Here's the
New to Ruby and ROR and loving it each day, so here is my
New to SharePoint. I'm trying to upload a document to SharePoint using it's CopyIntoItems
New to linux and trying to escape doing this the hard way. I have
New to Web2py, so my question might not be too clear. I'm trying to
New to javascript - I'm trying to generate random user ID's for my selenium
New list items are generated by JS. Each new list item comes in with

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.