Created
September 4, 2015 21:02
-
-
Save osbornm/0b2bae8aacb6e3e497ac to your computer and use it in GitHub Desktop.
uppercut.js Announcement
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
<!-- Console Binding: Prints to console.log very helpful for debuging --> | |
<div> | |
<!-- ko console: someValue --> <!-- /ko --> | |
</div> | |
<!-- Any and Empty Bindings: works like if binding but with less to type --> | |
<div data-bind="any: items"> You have Items</div> | |
<div data-bind="empty: items"> You have No Items</div> | |
<!-- href Binding: uses the attr binding under the covers but is less to type --> | |
<a data-bind="href: url">click here</a> |
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
// asObservable or asObservableArray: if passed an observable use that instance otherwise wrap it in a new observable | |
var myModel = function(options){ | |
var self = this; | |
self.observable = ko.asObservable(options.possibleObservable); | |
self.observableArray = ko.asObservableArray(options.possibleObservableArray); | |
return self; | |
} | |
// Trackable Observables: the ability to revert to a "good" value | |
var myForm = function(){ | |
var self = this; | |
self.value = ko.trackableObservable("initial value"); | |
self.array = ko.trackableObservableArray([]); | |
self.saveForm = function() { | |
// some ajax call or something | |
self.value.commit(); | |
self.array.commit(); | |
} | |
self.cancelForm = function() { | |
self.value.reset(); | |
self.array.reset(); | |
} | |
return self; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment