Created
February 27, 2013 05:11
-
-
Save osbornm/5045270 to your computer and use it in GitHub Desktop.
Knockout.js Trackable Observable
This file contains 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 model = ko.trackableObservable(value); | |
$(".cancel").click(function(){ | |
model.reset(); | |
}); |
This file contains 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
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