Last active
December 18, 2015 15:08
-
-
Save bhameyie/5801864 to your computer and use it in GitHub Desktop.
Using Coffeescript with KnockoutJS
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
class LoginFormViewModel | |
constructor: -> #from my many attempts, things works out best when you set them up from the constructor | |
@email= ko.observable("") | |
@pass= ko.observable("") | |
@logon= => #notice the fat arrow here | |
$.post '/Account/Login', | |
userId: @email() | |
password: @pass() | |
(data) -> $('body').append "Successfully posted to the page." | |
window.app = window.app || {} | |
window.app.LoginFormViewModel = LoginFormViewModel #exporting this guy is important as it makes it usable by external scripts |
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
(function() { | |
var LoginFormViewModel; | |
LoginFormViewModel = (function() { | |
function LoginFormViewModel() { | |
var _this = this; | |
this.email = ko.observable(""); | |
this.pass = ko.observable(""); | |
this.logon = function() { | |
$.post('/Account/Login', { | |
userId: _this.email(), | |
password: _this.pass() | |
}); | |
return function(data) { | |
return $('body').append("Successfully posted to the page."); | |
}; | |
}; | |
} | |
return LoginFormViewModel; | |
})(); | |
window.app = window.app || {}; | |
window.app.LoginFormViewModel = LoginFormViewModel; | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment