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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:26:45+00:00 2026-06-02T18:26:45+00:00

I’m studying a few JavaScript books, messing around with Node.js/Express/Jade/Backbone.js and experimenting with a

  • 0

I’m studying a few JavaScript books, messing around with Node.js/Express/Jade/Backbone.js and experimenting with a simple web app to keep track of poker tournaments so as to improve my novice JS skills, learn the previously mentioned technologies, and make a decent poker app at the same time. This is the code I have so far, using various sources around the web and PeepCodes first Backbone.js Screencast (I have node.js set up as a backend api):

(function ($) {
    window.Tournament = Backbone.Model.extend({});

    window.Tournaments = Backbone.Collection.extend({
        model: Tournament,
        url: '/tournaments'
    });

    window.tournaments = new Tournaments();

    // I removed this line once I attempted to bootstrap the data.
    window.tournaments.fetch(); 

    window.TournamentView = Backbone.View.extend({
        tagName: 'tr',
        className: 'tournaments',

        initialize: function () {
            _.bindAll(this, 'render');
            this.model.bind('change', this.render);
            this.template = _.template($("#tournament-template").html());
        },
        render: function () {
            var renderedContent = this.template(this.model.toJSON());
            $(this.el).html(renderedContent);
            return this;
        }
    });

    window.TournamentsView = Backbone.View.extend({
        initialize: function () {
            _.bindAll(this, 'render');
            this.collection.bind('reset', this.render);
        },
        render: function () {
            $(this.el).html($("#tournaments-template").html());
            (this.collection).each(function(tournament) {
                var view = new TournamentView({
                    model: tournament,
                    collection: this.collection
                });
                $("#tournaments").append(view.render().el);
            });
            return this;
        }
    });

    window.BackboneTournaments = Backbone.Router.extend({
        routes: {
            '': 'tournaments'
        },
        initialize: function () {
            this.tournamentsView = new TournamentsView({
                collection: window.tournaments
            });
        },
        tournaments: function () {
            $("#container").empty();
            $("#container").append(this.tournamentsView.render().el);
        }
    });

    $(function() {
        window.App = new BackboneTournaments();
        Backbone.history.start({});
    });

})(jQuery);

This works perfectly. I have a page with a populated table of poker tournaments. But after I attempt to bootstrap the data so that it isn’t fetching it after the page loads (and showing an unpopulated table for a fraction of a second) it no longer works. I’ve put the following code in the body of the app’s one page (app.jade, a Jade template), right after the container, (#container), used by Backbone.js and also removed the windows.tournaments.fetch(); line from the above code.

script(type="text/javascript")
    tournaments.reset(!{JSON.stringify(tournies)});

The tournies object is being passed to the Jade template (app.jade) from the Node.js route that renders it. Using Firebug, I can see that the reset() function is successfully getting the data in a JSON format and the table is being created by Backbone… but it isn’t being populated. Any help would be appreciated since I have absolutely no clue as to what the issue is. Also, I apologize if I made any mistakes in the structure of my question as I haven’t posted here before. Feel free to let me know if I have.

  • 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-02T18:26:45+00:00Added an answer on June 2, 2026 at 6:26 pm

    My first guess would be, that the document is not ready when you execute the script, try this:

     $(document).ready(function(){
       tournaments.reset(!{JSON.stringify(tournies)});
     });
    

    My second is that you need to look at the JSON data. Try to go to the console and add some of the Tournaments to the collection by hand and look what the results are, maybe there is some kind of error in parsing.

    A side note on your code, to organize your code better you should use the module pattern and name things with a schema like this: http://ricostacruz.com/backbone-patterns/#namespace_convention

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

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
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
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns 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.