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

The Archive Base Latest Questions

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

Hopefully this is an easy question. I’m trying to learn backbone and i’m stuck

  • 0

Hopefully this is an easy question. I’m trying to learn backbone and i’m stuck on a really simple thing. the render on the view never gets called when I update the collection by using the create method. I thought this should happen without explicitly calling render. I’m not loading anything dynamic, it’s all in the dom before this script fires. The click event works just fine and I can add new models to the collection, but the render in the view never fires.

$(function(){

window.QuizMe = {};

// create a model for our quizzes
QuizMe.Quiz = Backbone.Model.extend({
// override post for now
"sync": function (){return true},

});

QuizMe._QuizCollection = Backbone.Collection.extend({
model: QuizMe.Quiz,
});

QuizMe.QuizCollection = new QuizMe._QuizCollection

QuizMe.QuizView = Backbone.View.extend({

el:$('#QuizMeApp'),

template: _.template($('#quizList').html()),

events: {
  "click #addQuiz" : "addQuizDialog",
},

initialize: function() {
// is this right?
  _.bindAll(this,"render","addQuizDialog")
  this.model.bind('add', this.render, this);

},

addQuizDialog: function(event){
  console.log('addQuizDialog called')
  QuizMe.QuizCollection.create({display:"this is a display2",description:"this is a succinct description"});  
},

render: function() {
  console.log("render called")
},
});

QuizMe.App = new QuizMe.QuizView({model:QuizMe.Quiz})

});
  • 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-31T05:15:05+00:00Added an answer on May 31, 2026 at 5:15 am

    Your problem is that you’re binding to the model:

    this.model.bind('add', this.render, this);
    

    but you’re adding to a collection:

    QuizMe.QuizCollection.create({
        display:     "this is a display2",
        description: "this is a succinct description"
    });
    

    A view will usually have an associated collection or model but not both. If you want your QuizView to list the known quizzes then:

    1. You should probably call it QuizListView or something similar.
    2. Create a new QuizView that displays a single quiz; this view would have a model.
    3. Rework your QuizListView to work with a collection.

    You should end up with something like this:

    QuizMe.QuizListView = Backbone.View.extend({
        // ...
        initialize: function() {
            // You don't need to bind event handlers anymore, newer
            // Backbones use the right context by themselves.
            _.bindAll(this, 'render');
            this.collection.bind('add', this.render);
        },
        addQuizDialog: function(event) {
            this.collection.create({
                display:     "this is a display2",
                description: "this is a succinct description"
            });
        },
        render: function() {
            console.log("render called")
            // And some stuff in here to add QuizView instances to this.$el
            return this; // Your render() should always do this.
        }
    });
    
    QuizMe.App = new QuizMe.QuizView({ collection: QuizMe.QuizCollection });
    

    And watch that trailing comma after render, older IEs get upset about that and cause difficult to trace bugs.

    I’d give you a quick demo but http://jsfiddle.net/ is down at the moment. When it comes back, you can start with http://jsfiddle.net/ambiguous/RRXnK/ to play around, that fiddle has all the appropriate Backbone stuff (jQuery, Backbone, and Underscore) already set up.

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

Sidebar

Related Questions

hopefully this is a really easy question. I'm trying to achieve the following style
Hopefully this is an easy question to answer! I am trying to use GtkEntryCompletion
This is hopefully an easy question to answer for someone familiar with Mozilla, but
Hopefully an easy question, but I'd quite like a technical answer to this! What's
Hopefully this is an easy question. How can I define an XML type such
Hopefully this will be an easy question! I have two tables, a 'client(s)' table
I just started WPF this morning so this is (hopefully) an easy question to
Hopefully this question has an easy answer. It's probably something stupid I'm doing! In
Hopefully this is a quick and easy question to answer. Do I need the
Hopefully this is a brainlessly easy question, but it shows my lack of expertise

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.