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

The Archive Base Latest Questions

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

I have a Backbone view (see below) that I believe to be doing the

  • 0

I have a Backbone view (see below) that I believe to be doing the right thing

Index = Backbone.View.extend({
render: function() {
        var activities = new Activities();
        activities.fetch();
        var tpl = Handlebars.compile($("#activities-template").html());
        $(this.el).html(tpl({activities: activities.toJSON()}));
        return this;
      }
});

If execute each line in the render() function with Chrome JS console I get the expected result with the element I pass in getting populated with the template output. However, when I run this using the following

var i = new Index({el: $("body")})
i.render()

“i.$el” is completely empty–the HTML is not getting rendered like it does in console. Any ideas why?

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

    fetch is an AJAX call so there’s no guarantee that activities.toJSON() will give you any data when you do this:

    activities.fetch();
    var tpl = Handlebars.compile($("#activities-template").html());
    $(this.el).html(tpl({activities: activities.toJSON()}));
    

    Executing the code in the console probably gives the AJAX call time to return with something before you try to use activities.

    You should do two things:

    1. Fix your template to do something sensible (such as show a loading… message of some sort) if activities is empty.
    2. Attach your view’s render to the collection’s "reset" event:

      initialize: function() {
          // Or, more commonly, create the collection outside the view
          // and say `new View({ collection: ... })`
          this.collection = new Activities();
          this.collection.on('reset', this.render, this);
          this.collection.fetch();
      },
      render: function() {
          var tpl = Handlebars.compile($("#activities-template").html());
          this.$el.html(tpl({activities: this.collection.toJSON()}));
          return this;
      }
      

    I also switched to this.$el, there’s no need to $(this.el) when Backbone already gives you this.$el.

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

Sidebar

Related Questions

I have a view that includes a table. var newsIndexView = Backbone.View.extend({ ... });
I have the following code: var GoalPanelView = Backbone.View.extend({ // Bind to the goal
I have a standard list view setup with backbone that looks something like below.
I have html content like: <button class=submit>Save</button> and view like: var MyView = Backbone.View.extend({
I have a backbone view that calls to a sub-view: lr.MapView = Backbone.View.extend({ el:
I have following setup in my Backbone View: var SomeView; SomeView = Backbone.View.extend({ initialize:
I got this code: (function($){ var ListView = Backbone.View.extend({ el: $('body'), // el attaches
I have backbone view that binds an action to an element in the DOM.
I have a Backbone View that has a Collection as its Model. If the
I have a View (created using Backbone.View.extend) and a JSON object, I actually get

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.