Skip to content

Instantly share code, notes, and snippets.

@osbornm
Created February 27, 2013 05:11
Show Gist options
  • Save osbornm/5045270 to your computer and use it in GitHub Desktop.
Save osbornm/5045270 to your computer and use it in GitHub Desktop.
Knockout.js Trackable Observable
var model = ko.trackableObservable(value);
$(".cancel").click(function(){
model.reset();
});
ko.trackableObservable = function (initValue) {
var result = ko.observable(initValue);
result.committedValue = ko.observable(initValue);
result.commit = function () {
result.committedValue(result());
};
result.reset = function () {
result(result.committedValue());
};
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment