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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:30:09+00:00 2026-06-14T10:30:09+00:00

I’ve been trying my hand with Backbone.js, that didn’t go well so I’ve decided

  • 0

I’ve been trying my hand with Backbone.js, that didn’t go well so I’ve decided to start from the ground up, and getting my head round OOP with javascript, i thought i was doing pretty well btu now my templates just wont be rendered, I cant tell whether there is a problem with the template, the js, both, or the data!!

my template :

<script id="BudgetItemTemplate" type="text/x-handlebars-template">
{{#list data}}
 <div class="budget-item">
  <div class="item-info">{{type}}</div>
  <div class="item-spent">{{spent}}</div>
  <div class="item-budget">{{budget}}</div>
 </div>
{{/list}}   
</script>

my javascript :

var data = [];
var BudgetItems = [data];
var BudgetItemTemplateSource = $('#BudgetItemTemplate').html();
var BudgetItemTemplate = Handlebars.compile(BudgetItemTemplateSource);

function BudgetItem(type, spent, budget) {

   "use strict";
   this.type = type;
   this.spent = spent;
   this.budget = budget;

   this.editType = function (type) {
    this.type = type;
    return this;
};
this.editSpent = function (spent) {
    this.spent = spent;
    return this;
};
this.editBudget = function (budget) {
    this.budget = budget;
    return this;
};

 data.push({type: 'type', spent: 'spent', budget: 'budget'});
}

function BudgetItemList() {
this.BudgetItems = BudgetItems;
   this.render = function () {
    console.log('rendercalled')
      $('#iBudget').empty();
      $('#iBudget').append(BudgetItemTemplate(BudgetItems));
};
};

$(document).ready(function () {
var food = new BudgetItem('food', '0.00', '10.00');
var drink = new BudgetItem('drink', '10000.00', '450.00');
var bills = new BudgetItem('bills', '30.00', '50.00');
console.log(food.budget);
food.editType('basics');
console.log(food.type);
   console.log(BudgetItems);

var budgetlist = new BudgetItemList();    
budgetlist.render();
console.log(BudgetList.BudgetItems);

});

I just can’t get my head around why the template won’t render, I’ve tried several different ways of setting up my data, at the moment it is an array of an array, before I’ve had it as just an array. also in the template if tried using the ‘list’ helper with both a context and no context it both cases of data., i’ve used alerts throughout to debug and the problem seems to be with handlebars, but i cant figure it out! I would appreciate any comments, criticism or help.

  • 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-14T10:30:11+00:00Added an answer on June 14, 2026 at 10:30 am

    First of all, you have this in your template:

    {{#list data}}
        ...
    {{/list}}
    

    but {{#list}} isn’t defined by Handlebars and I don’t see a Handlebars.registerHelper call anywhere that would add such a custom helper. So I’ll assume that you meant to use the standard built in iterator {{#each}}:

    <script id="BudgetItemTemplate" type="text/x-handlebars-template">
        {{#each data}}
           <div class="budget-item">
               <div class="item-info">{{type}}</div>
               <div class="item-spent">{{spent}}</div>
               <div class="item-budget">{{budget}}</div>
           </div>
        {{/each}}   
    </script>​
    

    You’re on the right track with your “the template wants an object” idea but your implementation is a bit off. A compiled Handlebars template wants an object to use as a key/value namespace; so if you want to refer to {{x}} in a template then you need to call the template function like this:

    var html = template({
        x: 'some value'
    });
    

    Based on your template, you need to call the compiled template function with data like this:

    var html = template({
        data: [
            { type: 'pancakes', spent: 10, budget: 10 },
            { type: 'eggs',     spent:  5, budget:  1 },
            { type: 'stamps',   spent:  1, budget:  5 }
        ]
    });​​​​​​​​​​​​​​
    

    Here’s a demo of the template in action (excuse my horrifically bad color sense): http://jsfiddle.net/ambiguous/BVPRb/

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.