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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:40:21+00:00 2026-06-07T19:40:21+00:00

In Backbone, I have a collection which is populated with some JSON data which

  • 0

In Backbone, I have a collection which is populated with some JSON data which looks like below.

[
{
    "test1": {
        "fistName": "test",
        "lastName": "example"
    },
    "test2": {
        "fistName": "test",
        "lastName": "example"
    }
},
{
    "test1": {
        "fistName": "test",
        "fistName": "example"
    },
    "test2": {
        "fistName": "test",
        "fistName": "example"
    }
},

]

Currently im trying to add a new model to the collection holding data like the above.

This is the model.

Test = Backbone.Model.extend({
defaults : {
        test1: {
            firstName: null,
            lastName: null
        },
        test2: {
            firstName: null,
            lastName: null
        }
    },

});

Below is what I am trying

var test = new Test({test1: {firstName: $("#test1 option:selected").val(), score: $("#test1lastName").val()}}, {test2: {firstName: $("#test2 option:selected").val(), score: $("#test2lastName").val()}});

myCollection.add(test);

However doing this only populates test1 data and not test2 data. What would be the correct way to add both test1 and test2 data into the model, which could then be added to the collection.

Thanks

UPDATE

Just to clarify, test 1 and 2 are not separate objects, they are relevant to each other and need to be in the same model

  • 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-07T19:40:24+00:00Added an answer on June 7, 2026 at 7:40 pm

    Edit, depending on how your model is defined, if you format it as below you might able to debug a little better.

    var test = new TFS.Test({
        test1: {
            firstName: $("#test1 option:selected").val(),,
            lastName: '', // code for last name? 
            score: $("#test1lastName").val()
        },
        test2: {
            firstName: $("#test2 option:selected").val(),
            lastName: '', 
            score: $("#test2lastName").val()
        }
    });
    
    myCollection.add(test);
    

    I might be able to offer you a little more help if you give a better view of the entire action/process – i.e. what is triggering the creation of these models? Could there be a problem with jQuery, and your document not being ready?

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

Sidebar

Related Questions

I have a backbone application which, upon load, needs to fetch data from four
I have a view and collection like this: window.DmnView = Backbone.View.extend({ template: _.template($(#tmpl_dmnListItem).html()), events:
I have a backbone app with a view structure that looks like the following
I have a backbone collection which has a bunch of models with date attributes
I'm relativly new to Backbone.js I have a JSON like the picture shows !
I have Backbone.js collection that holds (for example) 30 items. I want to pass
I have a collection of flash cards that are tied to a Backbone collection.
I have a Backbone View that has a Collection as its Model. If the
I use backbone.js and have a model without a collection. In the view I
I have a backbone view which load subview. When I load a subview, I

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.