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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:18:58+00:00 2026-06-13T20:18:58+00:00

I’ve read many tutorials and made a search on the .net… but still I’m

  • 0

I’ve read many tutorials and made a search on the .net… but still I’m in trouble with Backbone.js. This is my simple scenario:

A Rails application responds to a GET request with a JSON collection of objects.
I want to dynamically build a list of table-rows with Backbone collections, when DOM is ready. This is the code is confusing me:

HTML part:

  <script type="text/template" id="tmplt-Page">
      <td>{{=title}}</td>
      <td>{{=description}}</td>
  </script>

Backbone’s script:

$(function(){
    var Page = Backbone.Model.extend({});

    var Pages = Backbone.Collection.extend({
        model: Page,
        url: '/pages'
    });
    var pages = new Pages([
        {title: 'ProvA1', description: ''},
        {title: 'ProvA2', description: ''}
    ]);

    var PageView = Backbone.View.extend({
        tagName: 'tr',
        template: _.template($('#tmplt-Page').html()),

        render: function() {
            this.$el.append(this.template(this.model.toJSON()));
            return this;
        }

    });

    var AppView = Backbone.View.extend({
        el: $("#results"),

        initialize: function () {
            _.bindAll(this, 'render');
            pages.on('reset', this.render)
        },

        render: function() {
            this.$el.empty();
            pages.each( function( page ) {

                var view = new PageView({
                  model : page
                });

                this.$el.append(view.render().el);

            });

            return this;
        }

    });

    var appview = new AppView;

});

Nothing renders on the screen.

There seem to be 2 problems:

1) fetch() is asynchronous, so the code is executed before the end of the ajax round-trip.

2) If I manually load some objects into the collection, this piece of code “this.template(this.model.toJSON())” does not substitute jSON attributes

EDIT :

To use mustache tags I wrote this code before all:

enter image description here

  • 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-13T20:19:00+00:00Added an answer on June 13, 2026 at 8:19 pm

    First, as you said, fetch() is asynchronous, but it triggers the ‘reset’ event when it completes, so you should add this in AppView.initialize:


    pages.on('reset', this.render)

    Second, you never insert the HTML of PageView anywhere. Add this in AppView.render:


    // at the beginning
    var self = this;
    // and in the forEach loop
    self.$el.append(view.el);

    Third, at the beginning of AppView.render, you should clear the content of this.$el.

    EDIT:

    You still had a couple issues:

    • You are using underscore templates with mustache tags ({{ }} -> <%= %>)
    • Missing var self = this in render
    • You are not calling appview.render() ! 🙂

    Here’s your code working on jsfiddle: http://jsfiddle.net/PkuqS/

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

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.