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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:02:53+00:00 2026-05-23T22:02:53+00:00

I am trying to learn backbone.js through the following example. Then I got stuck

  • 0

I am trying to learn backbone.js through the following example.
Then I got stuck at the point

ItemView = Backbone.View.extend

why you can use this.model.get?
I thought this is referring to the instance of ItemView that would be created. Then why would ItemView has a model property at all?!!

    (function($){
      var Item = Backbone.Model.extend({
        defaults: {
          part1: 'hello',
          part2: 'world'
        }
      });

      var List = Backbone.Collection.extend({
        model: Item
      });


var ItemView = Backbone.View.extend({

        tagName: 'li', 
        initialize: function(){
          _.bindAll(this, 'render');
        },
        render: function(){
          $(this.el).html('<span>'+this.model.get('part1')+' '+this.model.get('part2')+'</span>');
          return this;
        }
      });

      var ListView = Backbone.View.extend({
        el: $('body'), 
        events: {
          'click button#add': 'addItem'
        },
        initialize: function(){
          _.bindAll(this, 'render', 'addItem', 'appendItem'); 

          this.collection = new List();
          this.collection.bind('add', this.appendItem); 

          this.counter = 0;
          this.render();
        },
        render: function(){
          $(this.el).append("<button id='add'>Add list item</button>");
          $(this.el).append("<ul></ul>");
          _(this.collection.models).each(function(item){ 
            appendItem(item);
          }, this);
        },
        addItem: function(){
          this.counter++;
          var item = new Item();
          item.set({
            part2: item.get('part2') + this.counter
          });
          this.collection.add(item);
        },

        appendItem: function(item){
          var itemView = new ItemView({
            model: item
          });
          $('ul', this.el).append(itemView.render().el);
        }
      });

      var listView = new ListView();      
    })(jQuery);
  • 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-23T22:02:54+00:00Added an answer on May 23, 2026 at 10:02 pm

    The way Backbone implements the MVC architecture, Views may be attached to datasets(Collections) as well as individual model instances. Models typically represet records retrieved from database but in custom implementations may be any data objects.

    As you see, it is a very obvious question that when you actually have a view that represents a whole dataset so why should it be created out by nesting of views, each representing a single model instance. It is not necessary to do things in this way. You can have a non-nested view that represents a whole dataset which updates itself when any item in the collection is changed.

    But now, think … would it actually make sense to re-render the whole view just because one single entity in the collection has changed. Suppose you have a collection of thousands of records that is being represented by a datagrid view. Dont you think that re-rendering the entire datagrid with every change in collection will increase the latency of the application.

    So, it is in many cases a more preferred option to have a nested view object the way your example has implemented. So when a single model instance changes, the corresponding view has to be re-rendered and not the whole composite view.

    Also, if you want to provide the user, UI elements that operate on data sets as well as individual elements, it is more convenient and more sensible to implement in this nested view manner, where you would provide UI controls for operating on datasets at the composite view level and the controls for individual data elements at the element view level.

    Hope that clarifies your question.

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

Sidebar

Related Questions

I am trying to learn how to use MSBuild so we can use it
I'm trying to learn to use SDL for a little game I'm writing ,
I am trying to learn CodeIgniter to use for a shopping site, but I
Trying to learn C++ and working through a simple exercise on arrays. Basically, I've
I am trying to learn and build talking puppet iPhone application. The great example
I'm trying to learn to use only the keyboard with some applications, one of
Trying to learn a bit of CSS and I want a horizontal navbar and
In trying to learn how to create objects in ActionScript, I have had no
I'm trying to learn C. As a C# developer, my IDE is Visual Studio.
I am trying to learn the keyboard shortcuts in Visual Studio in order to

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.