Created
April 21, 2016 21:36
-
-
Save Tabares/06af8ef441e2dc42c756824f7b45d682 to your computer and use it in GitHub Desktop.
Collections in Backbone
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <script src="https://code.jquery.com/jquery-2.1.4.js"></script> | |
| <script src="//jashkenas.github.io/underscore/underscore-min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <h1>hello world</h> | |
| </body> | |
| </html> | |
| <script> | |
| var Model = Backbone.Model.extend({ | |
| }); | |
| var m2 = new Model({first : "steve"}); | |
| console.log(m2.get("first")); | |
| console.log(m2.toJSON); | |
| console.log(m2.attributes); | |
| //console.log(m2); | |
| var Model2 = Backbone.Model.extend({ | |
| url : "/users", | |
| defaults : { | |
| first : "Bob", | |
| last : "Tonks", | |
| email : "[email protected]" | |
| }, | |
| validate : function(atts, ops){ | |
| if(atts.first === "Steve"){ | |
| return "No Steve's allowed"; | |
| } | |
| } | |
| }); | |
| var m = new Model2(); | |
| m.on("change", function(){ | |
| console.log(m.isValid); | |
| }); | |
| console.log(m.isValid()); | |
| console.log(m.validationError); | |
| m.set("first", "Steve") | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment