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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:04:48+00:00 2026-06-08T07:04:48+00:00

I need to iterate over a backbone collection and get an array of objects

  • 0

I need to iterate over a backbone collection and get an array of objects that are derived from the models within the collection.

The problem is that I do not know how to let the collection access a method defined when creating the model definition inside the object given in: Backbone.Model.extend({})

This is an example of the architecture that I have so far:

// THE MODEL
var TheModel = Backbone.Model.extend({
    // THE FOLLOWING IS NOT AVAILABLE AS A METHOD OF THE MODEL:
    //     This isn't the actual method, but I though it might be helpful to
    //     to demonstrate that kind of thing the method needs to do (manipulate:
    //     map data and make it available to an external library)
    get_derived_object: function(){
        return this.get('lat') + '_' this.get('lon');
    }

});

// THE COLLECTION:
var TheCollection = Backbone.Collection.extend({
    // Use the underscore library to iterate through the list of
    //     models in the collection and get a list the objects returned from
    //     the "get_derived_object()" method of each model:
    get_list_of_derived_model_data: function(){
        return _.map(
            this.models,
            function(theModel){
                // This method is undefined here, but this is where I would expect
                //     it to be:
                return theModel.get_derived_object();

            }
        );
    }

});

I’m not sure where I am going wrong here, but I have a few guesses:
* The collection is not iterating over it’s models in the way that it should
* Public methods cannot be defined in Backbone.Model.extend({})
* I am looking in the wrong place for the public methods
* Some other architectural mistake derived from a misunderstanding of how Backbone.js is intended to be used

Any help is appreciated, thanks so much!

Edit

The problem was that there was actually a bug in this code. When the collection was populated, it did not have a reference to “TheModel” as its model type, so it created its own models.

This line of code needed to be added when the collection was defined: model: TheModel

var theCollection = Backbone.Collection.extend({
    model: TheModel,
    ...
});
  • 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-06-08T07:04:50+00:00Added an answer on June 8, 2026 at 7:04 am

    Instead of using:

    return _.map(
        this.models,
        function(theModel){
            // This method is undefined here, but this is where I would expect
            //     it to be:
            return theModel.get_derived_object();
         }
    );
    

    Why not use the built-in collection version:

    return this.map(function(theModel){
        return theModel.get_derived_object();
    });
    

    Not sure if that will help, but it’s worth a shot.

    And for the record, all methods defined in the first argument to new Backbone.Model( are “public”, so you’ve got the basics right.

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

Sidebar

Related Questions

In a multithreaded Java application I need to iterate over a collection of objects.
I need to iterate over a recordset from a stored procedure and execute another
I have a 3D array in Python and I need to iterate over all
Say I have components that I need to iterate through, for example From and
I need to iterate over an array for which the keys are non-consecutive: var
I need to iterate over a List of objects, doing something only for the
I need to iterate over an array of arbitrary rank. This is for both
Based on an associative array in a Bash script, I need to iterate over
I need to iterate over all request header objects and print it in App
I am writing a PHP function that will need to loop over an array

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.