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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:19:55+00:00 2026-06-18T08:19:55+00:00

In my Application, I have the following JSON data format: { Item: { property1:

  • 0

In my Application, I have the following JSON data format:

{
    Item: {
        property1: '',
        ...
    }
}

Following the solution of this stackoverflow.com answer, I modeled my Backbond.js models the following way:

App.Models.Item = Backbone.Model.extend({

});

App.Models.ItemData = Backbone.Model.extend({
    defaults: {
        'Item': new App.Models.Item
    }
});

I now want to bootstap the data to my App from the Backend system on the page load the following way:

var item = App.Models.ItemData({
    {Item: 
        {property1: 'data'}
    }
});

The problem I have now is that item.get('Item') returns a plain JavaScrip object and not a Backbone.Model object, because the defaults are overwritten. How can I create the Backbone.js object while ensuring that item.get('Item') is an App.Models.Item object?

I also have read that if you nest Backbone.Models, you should wirite custom getter methods, so the rest of your app dose not have to know about the internal data structure. If so, what is the right way to implement those setters and getters?

  • 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-18T08:19:56+00:00Added an answer on June 18, 2026 at 8:19 am

    You can override the parse method on your ItemData model. No defaults required. The parse method will initialize an empty model, if one is not passed:

    App.Models.ItemData = Backbone.Model.extend({
       parse: function(attrs) {
         attrs = attrs || {};
         if(!(attrs.Item instanceof App.Models.Item))
           attrs.Item = new App.Models.Item(attrs.Item);
    
         return attrs;
       }
    });
    

    And then initialize your ItemData model with the option parse:true:

    var item = new App.Models.ItemData({Item:{property1: 'data'}}, {parse:true});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following JSON returned in a variable called data. THIS IS THE
I have some JSON data which is in the following format: [ { id:
In my servlet I have the following code: response.setContentType(application/json);//set json content type PrintWriter out
I have the following JSON data being returned by a webservice: {d:[ {RelationshipManager:{},AdvisoryId:13,ClientId:22,UserId:13,AdvisoryMessage:Welcome!,Seen:false,Issued:\/Date(1312123970110)\/,Delivered:null,Importance:3}, {RelationshipManager:{},AdvisoryId:14,ClientId:22,UserId:13,AdvisoryMessage:A
I have to send the following data to webservice at URl The format of
I have the following code where i construct json data and send to the
I have the following ajax call to webservice to pass json data and get
I have the following application: I have 1 window. On that window I add
In my application I have the following tables: Posts id title content Users id
In my Rails 3.2.3 application I have the following code in the application.html.erb 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.