Forked from https://github.com/powmedia/backbone-deep-model (Thanks for the wonderful work @powmedia!)
The test cases are rewritten. This is primarily a browserify package. I'll work on making this work in other platforms if there is interest.
Improved support for models with nested attributes.
Allows you to get and set nested attributes with path syntax, e.g.
Triggers change events for changes on nested attributes.
- Backbone >= 1.0.0
- Underscore >= 1.4.4 or Lodash v2.4.x or Lodash v3.x.x
- Include Backbone and it's dependencies in your page/app.
Then just have your models extend from Backbone.DeepModel instead of Backbone.Model.
//Create models with nested attributesvar model =id: 123user:type: 'Spy'name:first: 'Sterling'last: 'Archer'otherSpies:name: 'Lana'name: 'Cyrril';//You can bind to change events on nested attributesmodel;//Wildcards are supportedmodel;//Use set with a path name for nested attributes//NOTE you must you quotation marks around the key name when using a pathmodel;//Use get() with path names so you can create getters laterconsole; // 'Spy'//You can use index notation to fetch from arraysconsole //'Lana'
Charles Davison - powmedia
- Lodash v3.x.x support.
- Significant refactor
- Add supprt for arrays in nested attributes (sqren)
- Trigger change events only once (restorer)
- Fix #68 Model or collection in attributes are eliminated when defaults are used
- Support Backbone 0.9.10
- Support Backbone 0.9.9 (mattyway)
- Add support for deep model defaults (mattyway)
- Allow nested attribute as Model identifier (milosdakic)
- Add AMD support (drd0rk)
- Added "change:*" event triggers for ancestors of nested attributes. (jessehouchins)
- JSHint linting (tony)
- Fix: undefined in setNested resulting from a recent change in backbone master. (evadnoob)
- Fix: #22 model.hasChanged() is not reset after change event fires
- Fix: #18 Setting a deep property to the same value deletes the property (mikefrey)
- Allow setting nested attributes inside an attribute whose value is currently null (sqs)
- Add DeepModel.keyPathSeparator to allow using custom path separators
- Check if the child object exists, but isn't an object. #12 (tgriesser)
- Model.changedAttributes now works with nested attributes.
- Fix getting attribute that is an empty object
- Update for Backbone v0.9.2