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

  • Home
  • SEARCH
  • 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 7755319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:32:18+00:00 2026-06-01T12:32:18+00:00

Assume I have a such json setting: { page:1, items:[ { name: ‘item1’, id:1

  • 0

Assume I have a such json setting:

{
  page:1,   
  items:[
    {  
      name: 'item1', 
      id:1
    }, 
    {
      name: 'item1', 
      id:2
    }, 
    {
      name: 'item1', 
      id:3
    }
  ] 
}

And a such modelling:

var Item = Backbone.Model.extend({
    defaults: {name:  "No name"}
});

var ItemCollection = Backbone.Collection.extend({
    model: Item,
    url: '/some/ajax/url',
});

After fetching this json, how can I map the items set as the collection of the ItemCollection and add the page number as an attribute to the collection?

  • 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-01T12:32:20+00:00Added an answer on June 1, 2026 at 12:32 pm

    As @asawyer mentioned, you have to override the parse method, but you don’t need to actually instantiate each item, Backbone can do that for you if you return the array of items.

    See the documentation for collection.parse

    parse collection.parse(response)

    parse is called by Backbone whenever a
    collection’s models are returned by the server, in fetch. The function
    is passed the raw response object, and should return the array of model attributes to be added to the collection.

    Your code could be written as

    var ItemCollection = Backbone.Collection.extend({
        model: Item,
        url: '/some/ajax/url',
    
        parse: function(data) {
            this.page=data.page;
            return data.items;
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have such simple model: class Foo(models.Model): name = models.CharField(max_length=25) b_date = models.DateField()
Assume I have a such model: class Foo(models.Model): name = models.CharField(ad,max_length=25) type = models.ForeignKey(Type)
assume I have a such html order <div id=header>>Header(logo, navigation menus etc)will be here,
Assume I have 2 time intervals,such as 16:30 - 20:00 AND 15:00 - 19:00,
Assume I have a form class SampleClass(forms.Form): name = forms.CharField(max_length=30) age = forms.IntegerField() django_hacker
Assume I have a such model: class Entity(models.Model): start_time = models.DateTimeField() I want to
Assume you have a list item, <li id=foo> which you want to fade from
Assume I have such folders rootfolder | / \ \ 01 02 03 ....
Assume I have a such struct: (define-struct node (value next)) ;and making 2 nodes,
Let's assume I have a class to be used as a decorator like such:

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.