KnockOut JS – Part 2
In Previous blog, explained about Observables, ComputedObservables, observableArray, Sunscribing.
- Bindings:
- Built in Bindings
- Text and Appearances (visible, text, html, css, style, attr)
- Form elements (click, event, submit, enable, disable, value, checked, options, selectedOptions, uniqueName)
- Control Flow (if, ifnot, foreach, with)
- Templates (Tradition JavaScript template in <script> tag, Template-less, comment-based syntax [Anonymous Templates])
- As like HandleBars.js, the KnockOut.js is supporting templates.
- We should not do foreach in ViewModel, it should be done in UI. So that the template data already bonded will not be bonded again.
- KnockOut.js will work without any external references like (JQuery)
- Instead of using <script> Templating, Knockout.Js is providing comment tags to do the same.
- Eg: <!—ko.foreach:tags à <!-- /ko à
- To delete the particular row in client side we can use ko.datafor(this);
- Parent Binding Contexts
- $data – Current data bound item
- $parent – item from parent binding context
- $parents – Array containing all parent bindings contexts
- $root – item at atop of the building
- Custom Bindings:
- The most useful extensibility point of knockout.Eg: ko.bindingHandlers.yourBindingName ={Init: function (element, valueAccessor, allBindingAccessor, viewModel) { //Code here }update: function (element, valueAccessor, allBindingAccessor, viewModel) { //Code here }}};
-
-
Comments
Post a Comment