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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:58:15+00:00 2026-05-25T06:58:15+00:00

I want my panels to re-render themselves when they are clicked. However, when I

  • 0

I want my panels to re-render themselves when they are clicked.

However, when I perform a click I get the following:

Uncaught TypeError: Cannot call method 'get' of undefined

It appears that the “this” that I’m logging is in fact the model itself:

_callbacks: Object
_changed: true
_escapedAttributes: Object
_previousAttributes: Object
attributes: Object
cid: "c0"
collection: r.d
id: "f5589ba4-a0aa-dd86-9697-30e532e0f975"
__proto__: n

I’m having trouble figuring out why the appropriate “this” isn’t preserved by passing my context into model.bind.

Here’s my code:

// Models
window.Panel = Backbone.Model.extend({

    defaults: function(){
        return {
            flipped: false,
        };
    },

    toggle: function(){
        this.save({flipped: !this.get("flipped")});
    },

});


// Collections

window.PanelList = Backbone.Collection.extend({

    model:Panel,

    localStorage: new Store("panels"),    

    flipped: function(){
        return this.filter(function(panel){ return panel.get("flipped"); })
    }   
});


// Global collection of Panels
window.Panels = new PanelList;

// Panel View

window.PanelView = Backbone.View.extend({ 

    tagName: 'div',

    template: _.template($("#panel-template").html()),  

    events: {
        "click" : "toggle"
    },

    initialize: function(){
        this.model.bind("change", this.render, this) 
        $(this.el).html(this.template(this.model.toJSON()));
    },     

    render: function(){    
        console.log(this);
        var flipped = this.model.get("flipped")
        if (flipped){
           $(this.el).addClass("flip"); 
        } else{
           $(this.el).removeClass("flip"); 
        }           
        return this   
    },

    toggle: function(){
        this.model.toggle(); 
    }
});   
  • 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-25T06:58:15+00:00Added an answer on May 25, 2026 at 6:58 am

    The backbone-y way of doing this is to use the _.bindAll(...) function provided by underscore:

    initialize: function(){
        _.bindAll(this, "render");
        this.model.bind("change", this.render) 
        $(this.el).html(this.template(this.model.toJSON()));
    }
    

    What _.bindAll does is documented here, but it is essentially built exactly for this purpose. If you want to have this properly set in all functions of the object, you can call _.bindAll(this) with no list of functions. I tend to have this global bind function in most of my views.

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

Sidebar

Related Questions

I want to perform the following task using JSF / Richfaces On click of
I want to place panels horizontally, but when I drag panels they are going
tl:dr version: Is there a way to get the panels to render as divs
I have a RichFaces component that I want to render after an Ajax call
I have 3 panels and I want to make drags on them. The problem
I want to create my own component which consists two other panels. One of
I am creating some sliding panels (accordion) and I want to slide the background
I have two update panels on a page. And I want to update both
Well the title is quite self explanatory. I want to build two panels one
I want to dynamically pick a facelet to render some item in my data

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.