Created
February 22, 2013 14:34
-
-
Save anonymous/5013832 to your computer and use it in GitHub Desktop.
Sample behavior of Backbone Nested.Model changedAttributes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Doc object from Nested.Model tests | |
| doc = new Klass({ | |
| gender: 'M', | |
| name: { | |
| first: 'Aidan', | |
| middle: { | |
| initial: 'L', | |
| full: 'Lee' | |
| }, | |
| last: 'Feldman' | |
| }, | |
| addresses: [ | |
| { | |
| city: 'Brooklyn', | |
| state: 'NY' | |
| }, | |
| { | |
| city: 'Oak Park', | |
| state: 'IL' | |
| } | |
| ] | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- | |
| Sample file with a very simple usage of changedAttributes showing that it's output is different than the one when running tthe tests | |
| --> | |
| <html manifest="" lang="en-US"> | |
| <head> | |
| <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
| <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script> | |
| <script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.10/backbone-min.js"></script> | |
| <script src="https://raw.github.com/afeld/backbone-nested/v1.1.2/backbone-nested.js"></script> | |
| </head> | |
| <body> | |
| </body> | |
| <script type="text/javascript"> | |
| var Books = Backbone.NestedModel.extend({}); | |
| var book = new Books({ | |
| title: 'Some Title', | |
| author: { | |
| name: 'Jhon', | |
| sure_name: 'Doe', | |
| email: 'jhon@test.org' | |
| }, | |
| pages: 120 | |
| }) | |
| var update = {title: 'Other Title', author: {name: 'Jane'}}; | |
| book.set(update); | |
| console.log('[INFO] got ', JSON.stringify(book.changedAttributes())); | |
| console.log('expected value was ', JSON.stringify(update)); | |
| </script> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment