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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:35:25+00:00 2026-05-21T21:35:25+00:00

I have a situation using backbone.js where I have a collection of models, and

  • 0

I have a situation using backbone.js where I have a collection of models, and some additional information about the models. For example, imagine that I’m returning a list of amounts: they have a quantity associated with each model. Assume now that the unit for each of the amounts is always the same: say quarts. Then the json object I get back from my service might be something like:

{
    dataPoints: [
         {quantity: 5 },
         {quantity: 10 },
         ...
    ],
    unit : quarts
 }

Now backbone collections have no real mechanism for natively associating this meta-data with the collection, but it was suggested to me in this question: Setting attributes on a collection – backbone js that I can extend the collection with a .meta(property, [value]) style function – which is a great solution. However, naturally it follows that we’d like to be able to cleanly retrieve this data from a json response like the one we have above.

Backbone.js gives us the parse(response) function, which allows us to specify where to extract the collection’s list of models from in combination with the url attribute. There is no way that I’m aware of, however, to make a more intelligent function without overloading fetch() which would remove the partial functionality that is already available.

My question is this: is there a better option than overloading fetch() (and trying it to call it’s superclass implementation) to achieve what I want to achieve?

Thanks

  • 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-21T21:35:25+00:00Added an answer on May 21, 2026 at 9:35 pm

    Personally, I would wrap the Collection inside another Model, and then override parse, like so:

    var DataPointsCollection = Backbone.Collection.extend({ /* etc etc */ });
    var CollectionContainer = Backbone.Model.extend({
        defaults: {
            dataPoints: new DataPointsCollection(),
            unit: "quarts"
        },
        parse: function(obj) {
            // update the inner collection
            this.get("dataPoints").refresh(obj.dataPoints);
    
            // this mightn't be necessary
            delete obj.dataPoints;
    
            return obj;
        }
    });
    

    The Collection.refresh() call updates the model with new values. Passing in a custom meta value to the Collection as previously suggested might stop you from being able to bind to those meta values.

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

Sidebar

Related Questions

I have a situation about in using ListView and found that if I set
The Situation (Ignore this it is boring): I have reports that I created using
Here is my situation. I have an app that is composed almost entirely using
I have a .NET 2.0 app (using C#) that shows some dynamically constructed HTML
I have a situation where I am defining an interface and then using that
I have a situation where I'm using some markup in 2 places on a
I have a situation where in MS Dynamics Crm it returns some objects using
I'm using Backbone with Backbone-relational. I have two models, Appointment and Client , where
We have a Backbone.js app that supports file uploads using plupload. The uploads are
Continuing my quest to learn more about Backbone.js I have arrived to a situation

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.