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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:42:35+00:00 2026-05-28T03:42:35+00:00

How can I bind a backbone view to a collection rather than a model?

  • 0

How can I bind a backbone view to a collection rather than a model? Do I need to wrap the collection in a model?

e.g.

If I have a backbone model Client and a collection of these called Clients

Client = Backbone.Model.extend({
    defaults: {
        Name: ''
    }
});

Clients = Backbone.Collection.extend({
    model: Client,
    url: 'Clients'
});

and a view

    var ClientListView = Backbone.View.extend({
        template: _.template($("#clients-template").html()),
        el: $('#clientlist'),

        initialize: function() {
            _.bindAll(this, 'render');

            this.collection = new Clients();
        },

        render: function( event ){
            $(this.el).html(this.template({ this.collection.toJSON()));

            return this;
        }
    });

then I can’t access each client element in the underscore template. However if I wrap the collection like this

$(this.el).html(this.template({ clients: this.collection.toJSON() }));

then I can. Is this the correct way to go about this? I would expect this to be a common scenario but I can’t find any examples on it, am I going about it the wrong way?

  • 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-28T03:42:35+00:00Added an answer on May 28, 2026 at 3:42 am

    Yes, you need to pass the wrapped collection.

    Addy Osmani is using similar approach in his Backbone Fundamentals examples – see for example this view and corresponding template:

    In the view:

    $el.html( compiled_template( { results: collection.models } ) );
    

    In the template:

    <% _.each( results, function( item, i ){ %>
       ...
    <% }); %>
    

    Another alternative is to have a view that will create separate view for each model in the collection. Here is an example from An Intro to Backbone.js: Part 3 – Binding a Collection to a View:

    var DonutCollectionView = Backbone.View.extend({
      initialize : function() {
        this._donutViews = [];
        this.collection.each(function(donut) {
          that._donutViews.push(new UpdatingDonutView({
            model : donut,
            tagName : 'li'
          }));
        });
      },
    
      render : function() {
        var that = this;
        $(this.el).empty();
    
        _(this._donutViews).each(function(dv) {
          $(that.el).append(dv.render().el);
        });
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Backbone.js have a segmented control-type UI element for each model's view. They
I have question how i can bind datagrid column to collection? dataGrid1.Columns.Add(new DataGridTemplateColumn {
I have a user control where the XAML of the control can bind to
I have a relatively simple Backbone handled message container. I can add messages, and
I have a backbone model which contains an array which I am updating with
In PHP, how can you bind using a property other than the default cn?
I have created a class so that I can bind it to a combo
I've got the following model with nested collection var Mdl = Backbone.Model.extend({ initialize: function()
I have my main activity that can bind a service and call a service
i have a nested listview, i can bind the selected item of the basic

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.