Forked from mxriverlynn/1-ModelWithChangedEvents.js
Created
February 21, 2016 11:03
-
-
Save sangkyunyoon/d555dc36e9c78a68fe2c to your computer and use it in GitHub Desktop.
Revisions
-
Derick Bailey revised this gist
Jun 15, 2011 . 1 changed file with 61 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ <html> <head> <script src="jquery-1.6.1.min.js"></script> <script src="json2.js"></script> <script src="underscore-min.js"></script> <script src="backbone-min.js"></script> <script language="javascript"> $(function(){ var SomeModel = Backbone.Model.extend({}); someModel = new SomeModel(); someModel.bind("change", function(model, collection){ alert("You set some_attribute to " + model.get('some_attribute')); }); someModel.set({some_attribute: "some value"}); var Credentials = Backbone.Model.extend({}); var LoginView = Backbone.View.extend({ el: $("#login-form"), events: { "click #login": "login" }, initialize: function(){ var self = this; this.username = $("#username"); this.password = $("#password"); this.username.change(function(e){ self.model.set({username: $(e.currentTarget).val()}); }); this.password.change(function(e){ self.model.set({password: $(e.currentTarget).val()}); }); }, login: function(){ var user= this.model.get('username'); var pword = this.model.get('password'); alert("You logged in as " + user + " and a password of " + pword); return false; } }); window.LoginView = new LoginView({model: new Credentials()}); }); </script> </head> <body> <form action="/login" id="login-form"> Username: <input type="text" id="username"><br> Password: <input type="password" id="password"><br> <button id="login">Login</button> </form> </body> </html> -
Derick Bailey revised this gist
Jun 15, 2011 . 2 changed files with 34 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ <form action="/login" id="login-form"> Username: <input type="text" id="username"><br> Password: <input type="password" id="password"><br> <button id="login">Login</button> </form> 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ var Credentials = Backbone.Model.extend({}); var LoginView = Backbone.View.extend({ el: $("#login-form"), events: { "click #login": "login" }, initialize: function(){ var self = this; this.username = $("#username"); this.password = $("#password"); this.username.change(function(e){ self.model.set({username: $(e.currentTarget).val()}); }); this.password.change(function(e){ self.model.set({password: $(e.currentTarget).val()}); }); }, login: function(){ var user= this.model.get('username'); var pword = this.model.get('password'); alert("You logged in as " + user + " and a password of " + pword); return false; } }); window.LoginView = new LoginView({model: new Credentials()}); -
Derick Bailey revised this gist
Jun 15, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ <form action="/login" id="login-form"> Username: <input type="text" id="username"><br> Password: <input type="password" id="password"><br> <input type="submit" id="login" value="Login"> -
Derick Bailey revised this gist
Jun 15, 2011 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ <form target="/login" action="post" id="login-form"> Username: <input type="text" id="username"><br> Password: <input type="password" id="password"><br> <input type="submit" id="login" value="Login"> </form> -
Derick Bailey revised this gist
Jun 15, 2011 . 2 changed files with 4 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,9 @@ var SomeModel = Backbone.Model.extend({}); someModel = new SomeModel(); someModel.bind("change", function(model, collection){ alert("You set some_attribute to " + model.get('some_attribute')); }); someModel.set({some_attribute: "some value"}); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ var someJSON = someModel.ToJSON(); -
Derick Bailey created this gist
Jun 15, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ var SomeModel = Backbone.Model.extend({}); someModel = new SomeModel(); someModel.bind("changed", function(attrs){ alert("You set some_attribute to " + attrs.some_attribute); }); someModel.set({some_attribute: "some value"});