| Annotations
                        
                                                                                    
                                                                                            |  | See elsewhere | 1 | See footnote |  
                                                                                            | ? | Optional | R | Ruby on Rails |  Viewmodel (JavaScript)
                        
                                    
                        | var vm = function(value) {
    this.variable = ko.observable(value);
};
ko.applyBindings(new vm('...'), DOM?);
 |  Templates (HTML)
                        
                                                                                    
                                                                                            | <div data-bind=”
 bindings ”>
 html </div>
 |  
                                                                                            | <!-- ko 
 bindings  -->
 html <!-- /ko -->
 |  
                                                                                            | <script type="text/html" id="
 T ">
 html </script>
 |  MSIEAlways quote  if
  in  { 'if': ... }
  bindings. Observables
                        
                                                                                    
                                                                                            |  | .isWritableObservable()
 |  
                                                                                            |  |  |  
                                                                                            | .subscribe(function(v) {}, 
 trg1? , 
 event2? )
  : s |  
                                                                                            | .notifySubscribers(
 currentvalue )
 |  
                                                                                            |  |  1 Default to  this
 .
2 change
  (default) or  beforeChange
 . ko.observableArray(array)
                        
                                                                                    
                                                                                            |  |  |  
                                                                                            |  |  |  
                                                                                            |  |  |  
                                                                                            |  |  |  
                                                                                            |  |  |  
                                                                                            |  |  |  
                                                                                            | .sort(function(
 a , 
 b ?)
  : -/0/+2 )
 |  
                                                                                            |  |  |  1 Get length:  ().length
 . Get item:  ()[
 index ]
 ko.computed(function() {})¹
                        
                            1 Use  ko.pureComputed
  if only observables. |  | Appearance bindings
                        
                                                                                    
                                                                                            |  |  |  
                                                                                            |  |  |  
                                                                                            | attr: { 
 attribute :
 value , 
 …  }
 |  
                                                                                            |  |  |  "template" appearance binding
                        
                                                                                    
                                                                                            |  |  |  
                                                                                            |  |  |  
                                                                                            |  |  |  
                                                                                            | afterRender: 
 function([DOM], context) |  
                                                                                            |  |  |  "foreach" control flow binding
                        
                                                                                    
                                                                                            |  |  |  
                                                                                            |  |  
                                                                                            |  |  |  
                                                                                            |  |  |  
                                                                                            | RincludeDestroyed
 : 
 bool |  Form bindings
                        
                                                                                    
                                                                                            |  | event: { 
 event : 
 function  }
 |  
                                                                                            |  |  
                                                                                            |  |  |  
                                                                                            |  |  |  
                                                                                            |  |  |  
                                                                                            |  |  |  1 Updates value on keypress, clipboard, etc. "options" form bindings
                        
                                                                                    
                                                                                            |  |  
                                                                                            |  |  |  
                                                                                            | optionsAfterRender: 
 function |  
                                                                                            |  |  |  
                                                                                            | RoptionsIncludeDestroyed
 : 
 bool |  1 Only for multiple selects. |  | Context variables
                        
                                                                                    
                                                                                            |  |  |  
                                                                                            |  |  |  
                                                                                            |  |  |  
                                                                                            |  |  |  
                                                                                            | $componentTemplateNodes
  : DOM array |  
                                                                                            |  | $parentContext
  : context |  1 Only available in  foreach
  loops. Writable ko.computed(…)
                        
                                    
                        | this.value = ko.observable();
this.double = ko.pureComputed({
  read: function () { return this.value * 2; },
  write: function(v) { this.value(v / 2); },
  owner: this?
});
 |  Builtin extenders
                        
                                                                                    
                                                                                            | .extend({ rateLimit: { timeout: 
 milliseconds , method: 
 method1?  } })
 |  
                                                                                            | .extend({ notify: 'always' });
 |  1 notifyAtFixedRate
 / notifyWhenChangesStop
 Custom extenders
                        
                                    
                        | ko.extenders.log = function(target, option) {
    target.subscribe(function(newValue) {
       console.log(option + ": " + newValue);
    });
    return target;
};
 |  | 
            
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment