Reputation: 371
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
Upvotes: 2
Views: 120
Reputation: 123
If you have the json file when the model is constructed, you could do
var m = new M({'attr1': json.type[1].new_type[2].attr1})
otherwise
var m = new M()
m.set({'attr1': json.type[1].new_type[2].attr1});
should work
Upvotes: 3