afeld / backbone-nested

A plugin to make Backbone.js keep track of nested attributes - looking for maintainers! https://github.com/afeld/backbone-nested/issues/157
https://afeld.github.com/backbone-nested/
MIT License
444 stars 83 forks source link

Initializing Nested Attributes - Backbone 1.0.0 #76

Closed ckm2k1 closed 10 years ago

ckm2k1 commented 11 years ago

I know you've only started work on the Backbone-0.9.9 branch but I think the same problem applies. When you initialize a model with a nested attribute and attempt to pass in an object, NestedModel fails on this line: 186: this.changed[attrStr] = newVal; because this.changed is not initialized yet at that point. I've hacked the problem by adding if(!this.changed) this.changed = {}; right before line 186 but i'm not sure this is a good solution.

Full example: var model = Backbone.NestedModel.extend({ defaults: { attr: {} } }); Init like this: var m = new model({ attr: { nestedAttr: "blah" } });

This example fails with: TypeError: Cannot set property 'attr.nestedAttr' of null

jslag commented 11 years ago

everything seems to work with this patch -- thanks!

vlapo commented 11 years ago

thanks :+1:

gkatsev commented 10 years ago

Master now has backbone 1.x support. Please try that. Thanks.

afeld commented 10 years ago

Should be fixed in v2.0.0. Feel free to reopen if that's not the case.