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

The Archive Base Latest Questions

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

I have a backbone view which load subview. When I load a subview, I

  • 0

I have a backbone view which load subview. When I load a subview, I would like to show a loader when the view fetch needed datas and hide the loader when the view is ready to render.

I did something like this :

var appView = Backbone.View.extend({
    showLoader: function() {
        // Code to show loader
    },

    hideLoader: function() {
        // Code to hide loader
    },

    loadSubView: function() {
        this.showLoader();
        var myView = new MySubView();
        this.$el.html(myView.render().el);
        this.hideLoader();
    }
});

For now, my sub-view load a collection and is implemented like this :

var mySubView = Backbone.View.extend({
    initialize: function() {
        this.myCollection.fetch({
            async: false
        });
    },

    render: function() {
        // Code to render
    }
});

My sub view load the collection synchronously because it is the only way I found to know when my view is “ready” to render but I think this is not the best way to use Backbone.

What schould I do ?

  • 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-06T10:46:32+00:00Added an answer on June 6, 2026 at 10:46 am

    There are several ways to do it.

    1. You can explicitly use the pubsub pattern. Something like this:

      var AppView = Backbone.View.extend({
          showLoader: function() {
              console.log('show the spinner');
          },
      
          hideLoader: function() {
              console.log('hide the spinner');
          },
      
          loadSubView: function() {
              this.showLoader();
              var subView = new SubView();
              subView.on('render', this.hideLoader);
              this.$el.html(subView.render().el);
      
          }
      });
      
      var SubView = Backbone.View.extend({       
          render: function() {
              console.log('a subView render');
              this.trigger('render');
              return this;
          }
      });
      
      var appView = new AppView({el: $('body')});
      appView.loadSubView();
      

      http://jsfiddle.net/theotheo/qnVhy/

    2. You can attach a function to the ajaxStart/ajaxStop events on the
      spinner itself:

      var AppView = Backbone.View.extend({
          initialize: function() {
              var _this = this;
              this.$('#spinner')
                  .hide()
                  .ajaxStart(_this.showLoader)
                  .ajaxStop(_this.hideLoader);
          }
          ...
      }
      
    3. Or you can use jQuery.ajaxSetup:

       var AppView = Backbone.View.extend({
              initialize: function() {
                  var _this = this;
                  jQuery.ajaxSetup({
                       beforeSend: _this.showLoader,
                       complete: _this.hideLoader,
                       success: function() {}
                  });
              }
          ...
        }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a backbone application which, upon load, needs to fetch data from four
I have a simple Backbone view which uses jQuery UI's buttons. For example I
I have a standard list view setup with backbone that looks something like below.
I have a backbone view - which when called presents a form $('#add-offer').click(function() {
I have a backbone app with a view structure that looks like the following
I would like to have a view that is extended to several other views
I have a parent backbone view which creates a new backbone view in its
I have a generic subclass of Backbone.View which has a close event listener. var
I have a Backbone view named Foo which has a scrollbar. When the scrollbar
I have a Backbone View which handles a registration component, because this required a

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.