Created
September 5, 2012 02:56
-
-
Save kenstone/3629588 to your computer and use it in GitHub Desktop.
Knockout View Model Method Call with deferreds
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
var viewModel = function() { | |
var self = this; | |
self.description = ko.observable(); | |
self.get = function(words) { | |
return $.ajax({ | |
url: "/echo/json", | |
dataType: "json", | |
type: "POST", | |
data: { | |
"text": words | |
}, | |
success: function(data) { | |
self.description(words); | |
}, | |
error: function(data) { | |
} | |
}); | |
}; | |
}; | |
$(function() { | |
var instance = new viewModel(); | |
ko.applyBindings(instance); | |
$.when(instance.get('something')).then(function() { | |
instance.description('post promise'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment