Search code examples
javascriptjsonbackbone.js

Adding values to individual attributes of Backbone Model


Suppose I have a JSON file which contains a number of attributes like this:

json.type[1].next_type[1].attribute

And I want to change a specific value of a backbone model which is to contain these attributes.

var M = Backbone.Model.extend({
defaults:{
    attr1: null,
    attr2: null,
    attr3: null }

How would I make attr1 = json.type[1].new_type[2].attr1 ?

Thanks


Solution

  • var m = new M({ attr1: json.type[1].new_type[2].attr1 });