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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:29:15+00:00 2026-05-31T11:29:15+00:00

I render a collection of backbone models in a list view, where each model

  • 0

I render a collection of backbone models in a list view, where each model has its own listItemView such as.

 var els = [];      
    _.each(this.collection.models, function(model){                     
        var view = new TB_BB.RequestItemView({model : model});
        els.push(view.render().el);
    });
    $('#request-list').append(els);

Each of the ItemsView can be expanded on a click event (where a call to the server is made) such as.

showDetails : function() {      

    var m = new TB_BB.RequestDetails({id : this.model.get('id')});
    var outerthis = this;
    m.fetch({success : function() {
        var det = new TB_BB.RequestDetailsView({model : m, el : outerthis.el, current : outerthis, template : '#request-expanded-template'});           
        det.render();       

    }});                
}

So the logic is that this expanded view opens in the el of the current item. You may have noticed that I am passing a reference to the current view (outerthis) this was to avoid me having zombies of this view when closing expanding view.

So in the expanded view we have a ‘hide’ method which should hide the expanded view and show the original element such as (where current is the reference to the non-expanded view).

hideDetails : function() {
    $(this.el).empty();     
    this.options.current.render();
}

I’m pretty sure this is not the best way of doing this – but not sure what would be the best way? In this case there are no zombies when calling the hidedetails (as its referencing the original view). However I am guessing that each time the ‘showDetails’ view is called and closed a new zombie exists? Could anyone enlighten what would be a better way of having expanded views of a list?

  • 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-05-31T11:29:16+00:00Added an answer on May 31, 2026 at 11:29 am

    I’ve had a similar case in the past where I had to render a tree type structure, with list items opening to show sub-lists and closing again. The way I implemented the solution was to have the something like this as the html structure:

    <div class="list-item">
       <div class="handle closed" />
       <span><%= title %></span>
       <div class="sub-list" />
    </div>
    

    So each list item was rendered with an empty element for the sub view. Then in the click handler I would check if this list-item already has created a view for the sub-list, if yes just show the sub-list element; if not, create sub list view, which renders ajax-loader.gif and call collection.fetch to fetch data.

    So my recommendation is to use separate dom elements, create subviews lazily and just hide the dom element when you close something, keeping a reference to the view.

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

Sidebar

Related Questions

Using Backbone I can fetch the Collection like below and render a Backbone View
I'm trying to render a Backbone.js collection as a select list using an Underscore.js
I'm using backbone with the backbone-rails gem which does its own templating and project
I have a view and collection like this: window.DmnView = Backbone.View.extend({ template: _.template($(#tmpl_dmnListItem).html()), events:
Currently when I insert a list of views in backbone I do : var
I've got a backbone model with contains a collection. The output from the console
I'm trying to make a quick sample Backbone.js app that has a Post model,
I want to display a simple list of languages. class Language extends Backbone.Model defaults:
I have a backbone collection and when I remove a model from the collection,
I have collection of Questions as List. For each question I want to show

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.