3

How to get support for dot notation/nested objects in backbone model. The plugins that are available are buggy and wondering if backbone would ever support

person = { name : {first: 'hon',last:'son'}}
model = new Backbone.Model(person)
model.get('name.first')
model.set('name.first','bon') 
coool
  • 8,085
  • 12
  • 60
  • 80
  • Did you try this model.get('name').first ? – Jeffpowrs Sep 03 '13 at 13:56
  • I can do that..but setting would not trigger a change..nor can I bind to listen for change in attributes of object.. – coool Sep 03 '13 at 13:57
  • I think there is already a post that answers your question. http://stackoverflow.com/questions/6351271/backbone-js-get-and-set-nested-object-attribute – Jeffpowrs Sep 03 '13 at 14:01

2 Answers2

2

There are two plugins to get the job done:

Both handle getting and setting attributes and change events for dot notation.

VuesomeDev
  • 4,095
  • 2
  • 34
  • 44
0

I did that if i were you:

var nameObj = model.get('name')
nameObj.first = bon
model.set('name', nameObj)
Ulug'bek
  • 2,762
  • 6
  • 31
  • 59