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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:23:18+00:00 2026-06-04T03:23:18+00:00

I was putting up a sample code for one of questions here on and

  • 0

I was putting up a sample code for one of questions here on and i stumbled with this problem. I definitively know something simple is missing but can’t reason out what. Rendering a simple collection does not show in the DOM but does during debugging in the console.Code is bit long(verbose) so did not want to replicate here. Have a jsfiddle please see that

JsFiddle

http://jsfiddle.net/zRSg3/2/

The views look like this:

/*Provides visual display of category*/
var categoryView = Backbone.View.extend({
    tagName: "div",
    template:_.template($("#categoryView").html()),
    className: "category-view",
    initialize: function() {
    },
    render: function() {
        $(this.el).empty().html(this.template(this.model.toJSON()));
        return this;
    }    
});

/*visual display of how categories looks*/
var categoriesView = Backbone.View.extend({
    el: "#accordian",
    render: function() {    
        this.collection.each(this.renderEach,this);
        return this;
    },
    renderEach: function(mod,index,arr) {
        $(this.el).empty().append(new categoryView({model:mod}).render().el);
    },
    events: {
        "load": "initAccordian"
    },
    initAccordian: function() {

    }
});

and they’re rendered like this:

var userCategoriesView = new categoriesView({collection:userCategories});
userCategoriesView.render();​
  • 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-04T03:23:19+00:00Added an answer on June 4, 2026 at 3:23 am

    Your first problem is that you can’t spell “accordion” (but neither can I so don’t feel too bad):

    el: "#accordian",
    

    should be:

    el: "#accordion",
    

    Your next problem is that renderEach is clearing out all the HTML on each step through your collection so you’ll end up with only the last element rendered:

    renderEach: function(mod,index,arr) {
        $(this.el).empty().append(new categoryView({model:mod}).render().el);
    },
    

    Drop the empty() call:

    renderEach: function(mod,index,arr) {
        $(this.el).append(new categoryView({model:mod}).render().el);
    },
    

    Another problem you’ll have is that there is no load even on your #accordion so this:

    events: {
        "load": "initAccordian"
    },
    

    won’t do anything. You’ll have to call initAccordian yourself (and you’ll probably want to fix the spelling too); if you need to wait until the browser has control again before initAccordion is called then you could use a setTimeout with a time of zero:

    render: function() {
        var that = this;
        this.collection.each(this.renderEach,this);
        setTimeout(function() { that.initAccordion() }, 0);
        return this;
    }
    

    This “timeout of zero” hack is useful if you need the browser to get everything positioned and sized before you can finish your work.

    Also, newer versions of Backbone provide a jQuery-ified version of this.el in this.$el in your views so you don’t need to $(this.el).

    Here’s a cleaned up version of your fiddle: http://jsfiddle.net/ambiguous/EMMrD/

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

Sidebar

Related Questions

I'm sure I'm missing something very simple on this one. After banging my head
I've been stuck on this likely very simple problem, but haven't gotten anywhere with
Is there a simple way of putting source code into a repository and then
This should be a very simple procedure of putting a container in the centre
This is probably a simple question, but how do you iterate through an array,
This is probably a simple question, but it's driving me crazy! I have a
Its one of those simple questions that bug the most. I have the following
I have a class with a few simple structs like this (simplified code) inside
Consider this sample code: <div class=containter id=ControlGroupDiv> <input onbeforeupdate=alert('bingo 0'); return false; onclick=alert('click 0');return
I know this question has been asked but I haven't found any satisfactory answers.

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.