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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:43:41+00:00 2026-05-27T05:43:41+00:00

I have a view which doesn’t seem to want to render as the model’s

  • 0

I have a view which doesn’t seem to want to render as the model’s change event is not firing.

here’s my model:

var LanguagePanelModel = Backbone.Model.extend({
    name:       "langpanel",
    url:        "/setlocale",
    initialize: function(){
        console.log("langselect initing")
    }
})

here’s my view:

var LanguagePanelView = Backbone.View.extend({
    tagName:        "div",
    className:      "langselect",
    render:         function(){
        this.el.innerHTML = this.model.get("content");
        console.log("render",this.model.get(0))
        return this;
    },
    initialize : function(options) {
        console.log("initializing",this.model)
        _.bindAll(this, "render");
        this.model.bind('change', this.render);
        this.model.fetch(this.model.url);
  }
});

here’s how I instantiate them:

if(some stuff here)
{
   lsm = new LanguagePanelModel();
   lsv = new LanguagePanelView({model:lsm});
}

I get logs for the init but not for the render of the view?
Any ideas?

  • 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-27T05:43:42+00:00Added an answer on May 27, 2026 at 5:43 am

    I guess it’s about setting the attributes of the model – name is not a standard attribute and the way you’ve defined it, it seems to be accessible directly by using model.name and backbone doesn’t allow that AFAIK. Here are the changes that work 🙂 You can see the associated fiddle with it too 🙂

    $(document).ready(function(){
    var LanguagePanelModel = Backbone.Model.extend({
        //adding custom attributes to defaults (with default values)
        defaults: {
            name:       "langpanel",
            content: "Some test content"  //just 'cause there wasn't anything to fetch from the server
        },
    
        url:        "/setlocale",
    
        initialize: function(){
            console.log("langselect initing"); //does get logged
        }
    });
    
    var LanguagePanelView = Backbone.View.extend({
        el: $('#somediv'), //added here directly so that content can be seen in the actual div
    
        initialize : function(options) {
            console.log("initializing",this.model);
            _.bindAll(this, "render");
            this.render(); //calling directly since 'change' won't be triggered
            this.model.bind('change', this.render);
            //this.model.fetch(this.model.url);
        },
    
        render: function(){
            var c = this.model.get("content");
            alert(c);
            $(this.el).html(c); //for UI visibility
            console.log("render",this.model.get(0)); //does get logged :)
            return this;
        }
    });
    
    var lpm = new LanguagePanelModel();
    var lpv = new LanguagePanelView({model:lpm});
    
    }); //end ready
    

    UPDATE:

    You don’t need to manually trigger the change event – think of it as bad practice. Here’s what the backbone documentation says (note: fetch also triggers change!)

    Fetch

    model.fetch([options])
    Resets the model’s state from the server.
    Useful if the model has never been populated with data, or if you’d
    like to ensure that you have the latest server state. A “change” event
    will be triggered if the server’s state differs from the current
    attributes. Accepts success and error callbacks in the options hash,
    which are passed (model, response) as arguments.

    So, if the value fetched from the server is different from the defaults the change event will be fired so you needn’t do it yourself. If you really wish to have such an event then you can use the trigger approach but custom name it since it’s specific to your application. You are basically trying to overload the event so to speak. Totally fine, but just a thought.

    Change

    model.change()
    Manually trigger the “change” event. If you’ve been
    passing {silent: true}
    to the set function in order to aggregate rapid
    changes to a model, you’ll want to call model.change() when you’re all
    finished.

    The change event is to be manually triggered only if you’ve been suppressing the event by passing silent:true as an argument to the set method of the model.

    You may also want to look at ‘has changed‘ and other events from the backbone doc.

    EDIT Forgot to add the updated fiddle for the above example – you can see that the alert box pops up twice when the model is changed by explicitly calling set – the same would happen on fetching too. And hence the comment on the fact that you “may not” need to trigger ‘change’ manually as you are doing 🙂

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

Sidebar

Related Questions

I have a table view controller which doesn't let me manually scroll to the
I need to have a view which shows first before other views but doesn't
I have a table view which I want to bring up in edit mode
I have a view model which uses custom attributes such as public int Id
I have a view which contains a form, the form posts and the data
I have a view which is composed of top, left and bottom headers and
I have a view which was working fine when I was joining my main
I have a view which I built in Interface builder with a tableview and
I have an admin view which contains four foreign keys each with a few
I have a view from which I am selecting three columns. Of these three

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.