• Stars
    star
    648
  • Rank 69,480 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 13 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Improved support for models with nested attributes.

NOTE: I no longer have time to maintain this module. Please see the forks list for actively maintained projects, such as https://github.com/kahwee/backbone-deep-model

backbone-deep-model

Improved support for models with nested attributes.

Allows you to get and set nested attributes with path syntax, e.g. user.type.

Triggers change events for changes on nested attributes.

Dependencies

Backbone >= 0.9.10

Installation

  1. Include Backbone and it's dependencies in your page/app.
  2. Include distribution/deep-model.min.js

Usage

Then just have your models extend from Backbone.DeepModel instead of Backbone.Model.

Example code:

//Create models with nested attributes
var model = new Backbone.DeepModel({
    id: 123,
    user: {
        type: 'Spy',
        name: {
            first: 'Sterling',
            last: 'Archer'
        }
    },
    otherSpies: [
        { name: 'Lana' },
        { name: 'Cyrril' }
    ]
});

//You can bind to change events on nested attributes
model.bind('change:user.name.first', function(model, val) {
    console.log(val);
});

//Wildcards are supported
model.bind('change:user.*', function() {});

//Use set with a path name for nested attributes
//NOTE you must you quotation marks around the key name when using a path
model.set({
    'user.name.first': 'Lana',
    'user.name.last':  'Kang'
});

//Use get() with path names so you can create getters later
console.log(model.get('user.type'));    // 'Spy'

//You can use index notation to fetch from arrays
console.log(model.get('otherSpies.0.name')) //'Lana'

Author

Charles Davison - powmedia

Contributors

Changelog

master:

  • Add supprt for arrays in nested attributes (sqren)

0.11.0:

  • Trigger change events only once (restorer)

0.10.4:

  • Fix #68 Model or collection in attributes are eliminated when defaults are used

0.10.0:

  • Support Backbone 0.9.10

0.9.0:

  • Support Backbone 0.9.9 (mattyway)
  • Add support for deep model defaults (mattyway)

0.8.0:

  • 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)

0.7.4:

  • 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)

0.7.3:

  • Add DeepModel.keyPathSeparator to allow using custom path separators

0.7.2:

  • Check if the child object exists, but isn't an object. #12 (tgriesser)

0.7.1:

  • Model.changedAttributes now works with nested attributes.
  • Fix getting attribute that is an empty object

0.7:

  • Update for Backbone v0.9.2

More Repositories

1

backbone-forms

Form framework for BackboneJS with nested forms, editable lists and validation
JavaScript
2,167
star
2

backbone.bootstrap-modal

Bootstrap Modal wrapper for use with Backbone.
JavaScript
183
star
3

buildify

Builder for creating distributable JavaScript files from source. Concatenate, wrap, uglify.
JavaScript
123
star
4

mongoose-fixtures

Fixture loader for NodeJS' Mongoose ODM. Check pow-mongodb-fixtures instead to load data straight to MongoDB, skipping Mongoose.
JavaScript
112
star
5

pow-mongodb-fixtures

Easy JSON fixture loading for MongoDB. Makes managing relationships easier.
JavaScript
108
star
6

mongoose-taggable

Simple tagging plugin for Mongoose
JavaScript
23
star
7

nodeunit-httpclient

HTTP response testing for NodeUnit
JavaScript
16
star
8

mongoose-plugins

Plugins for NodeJS' Mongoose ODM: Slugger, Timestamper, Authenticator, Pointer (DBRefs), Validators
JavaScript
15
star
9

backbone.xview

Easy to use view manager for Backbone. Effortless nested views and templating.
JavaScript
10
star
10

pow-underscore

Underscore with mixins and path support
JavaScript
7
star
11

pow-mongoose-plugins

Plugins for Mongoose (NodeJS MongoDB ORM)
JavaScript
6
star
12

mocker

NodeJS mocking library
JavaScript
3
star
13

backbone.screenmanager

Manage mobile Backbone views with menus, overlays and transitions
JavaScript
3
star
14

pow-express-utils

Express utils
JavaScript
3
star
15

powActivatablePlugin

Symfony 1.4 plugin: Adds the Activatable Doctrine behavior which is useful for when you want to hide or 'switch off' certain records. For example, for moderation, approval etc. This adds an is_active column (can be renamed) and helper methods to the Table model class for modifying queries.
PHP
3
star
16

powJSONActions

A simple Symfony 1.4 plugin to make responding to JSON requests and debugging easier.
PHP
2
star
17

update-props

Updates a whitelist of an object's properties and returns changes, if any
JavaScript
1
star
18

heroku-utils

Utilities for apps running on Heroku
JavaScript
1
star
19

pow-mongoose-timestamps

Add created and updated timestamps to Mongoose models
JavaScript
1
star