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

  • Home
  • SEARCH
  • 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 7681491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:21:14+00:00 2026-05-31T18:21:14+00:00

i have a simple template that i populate with some data then im trying

  • 0

i have a simple template that i populate with some data then im trying to append it before one did, but it seems to stop working.

here is the jsfiddle

and the code:

<ul class="wall_message">
    <li id="168" class="msgid">
        <div id="commentbox2">
        </div>
    </li>
    <!-- in this case the json will be added only before `commentbox2`-->
    <li id="168" class="msgid">
        <div id="commentbox3">
        </div>
    </li>
</ul>




<script id="comment" type="text/x-handlebars-template">
                {{#each this}}
                        <div class="commentsp">{{comment}}</div>
                {{/each}}
</script>


<script>

//right now this json has only one main key (5), but it could have more
var data = {"5":
            {"id":"2", "comment":"xxxxxxxx"}
           }

/initiate the template
var template = Handlebars.compile( $('#comment').html() );

// place the json data in the template. the template will iterate through
msg = template(data);

jQuery.each(data, function(i, val) {
    console.log(val.id)

    //find the div with commentbox2 and add the msg before
    $('div#commentbox'+val.id).before(msg);
});
</script>

im not sure what i am doing wrong in this case.

any ideas?

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-05-31T18:21:15+00:00Added an answer on May 31, 2026 at 6:21 pm

    I have tried to resolv your problem.

    Your Json seems not “handlebar-compatible” for me.
    I have rewrited it with a root element, which will be used in the {{#each}} statement.

    var data = { 
        'items': [
            {"id":"2", "comment": "xxxxxxxx"}, 
            {"id":"3", "comment": "yyyyyyy"}
        ]
    };
    
    var template = Handlebars.compile( $('#comment').html() );
    var msg = template(data);
    
    jQuery.each(data.items, function(i, val) { 
        $('div#commentbox'+val.id).before(msg);
    });
    

    See the complete demo here http://jsfiddle.net/nsvT3/11/

    I hope it’s what you want.

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

Sidebar

Related Questions

I have simple template that's html mostly and then pulls some stuff out of
my problem is a simple one. I have a class template that holds a
I have a simple erb template that pulls information from a (Grit) git repository.
I have the following template that I am trying to get working, I have
I have a simple mustache template setup that takes an object player and creates
I'm using ajax requests to populate modal popup windows with data that users have
I have a simple template example that is as follow: template<class T> class A
I have a simple view-based app from that template. It has nothing else in
I have the following simple button with an image as the template. The problem
I have created a simple wcf service which used the WCF Service Library template.

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.