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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:04:43+00:00 2026-06-04T11:04:43+00:00

I am creating a web application using backbone.js. I have two tabs. Tab 1

  • 0

I am creating a web application using backbone.js. I have two tabs. Tab 1 is a backbone.js view and tab2 is another backbone view (of the same kind).

Both the views are loaded to the same div element in the page. Currently what I do is, when user change the tab, I detect it using the backbone router. Then router does a check to see if a view is already there, or should it be created.

I created a object manager object, who store the view object based on a key (key is the tab name)

App.ObjectManager.getContentView = function (tabId) {

    return App.ObjectManager.ContentHash[tabId];
};

App.ObjectManager.setContentView = function(tabId, view) {

    App.ObjectManager.ContentHash[tabId] = view;
};

App.ObjectManager.hasContentView = function(tabId) {

    if(App.ObjectManager.ContentHash[tabId]==undefined) {
        return 0;
    }

    else{
        return 1;
    }
};

Here is what I do to create and store the view to list object. This code is called every time a tab is clicked, and router detects the change.

$("#myDiv").html(""); 

if(App.ObjectManager.hasContentView(tabId)==0) {  //View is not in the lookup table

    console.log("View is not created yet. So we need to create");
    content = new App.MyBackboneView(); //create a new view
    App.ObjectManager.setContentView(tabId, content); //Store the view
}

else {

    console.log("View is already created..So we read it and show it");
    content = App.ObjectManager.getContentView(tabId);

}

//Now, we add the view to the main div

$("#myDiv").append(content.el);

The code above works by showing the view to the myDiv. and I can see the values of text boxes and radio buttons, etc being shown.

The only thing – event handling don’t work. So, if I have a button in the view that is added an event handler, the event don’t get called when the view is rendered from the saved object. First time when the view gets shown, click event is handling.

For eg, I have this button in the view “Say My Name!”

events: {
    "click #say": "sayName"
},

sayName: function() {
    console.log("I click say Name");
}

First time the view gets loaded, when I press the button, console show me the log. When I come back to the tab again, and this time view is shown from the list object, the click event don’t work.

Is my code having any problem ?

Hope you can give me some way how to store the view and I can reuse the view again.

Thanks.

  • 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-04T11:04:44+00:00Added an answer on June 4, 2026 at 11:04 am

    When creating a view you empty myDiv content

    $("#myDiv").html("");
    

    I think this action automatically removes all bindings that you set in your View earlier. It’s actually quite a common problem with Backbone – this framework sets event listeners to dom elements in the view.

    Probably easiest way to deal with this issue is to create a parent View for #myDiv as a whole and set events in there.

    View structure may look like that:

    TabsView (set events here)
    |
    – Tab View 1 (render content)
    – Tab View 2 (render content)

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

Sidebar

Related Questions

I'm creating a web application which loads tabs using AJAX. My problem is that
I am creating a web application using Netbeans and servlets. I have used some
I am creating a web application using EJBs and servlets. I have a page
I am creating a web chat application using asp.net vb. I have got the
I am creating a web application using zend, here I create an interface from
I am creating a web application using HTML5 canvas to draw images ( like
I am creating a login system for a web application using PHP. My question
I am creating an application which involves so many web-service calls. I am using
I am creating a web application using Form Authentication of Asp.Net with C# and
I am creating a web application using ASP.Net. I am using session in my

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.