Knockout JS 2.0.0 released – Dynamic JavaScript-UIs using Data Binding

The Knockout JS Team recently released version 2.0.0 of their JavaScript data binding framework.

Knockout JS is a small Javascript library that offers declarative data binding for your HTML code. It enables you to separate you HTML code from your data and UI logic, offering automatic UI refresh and dependency tracking.
I’m going to write an introductional blog post on KnockoutJS soon. In the meantime, check out the great introduction video of the creator Steve Sanderson.

The new features of version 2.0.0 are:

  • Control flow bindings
    You don’t need a template engine like jquery-tmpl any longer. Simply use the new control flow bindings if, ifnot, with, and foreach.

    <ul data-bind="foreach: products">
            <strong data-bind="text: name"></strong>
            <em data-bind="if: manufacturer">
                &mdash; made by <span data-bind="text:"></span>
  • Containerless control flow
    You can now avoid using a container element for bindings like foreach by using the new comment-based control flow syntax.

        <li><strong>Here is a static header item</strong></li>
        <!-- ko foreach: products -->
            <em data-bind="text: name"></em>
  • Access to parent binding contexts
    You can now access properties that exist at the upper levels of binding via the new pseudo-variables $data, $parent, $parents and $root.
  • Cleaner event handling
    There is now a cleaner, more declarative syntax for event handling bindings that does no longer require to write inline function literals.
  • Binding providers
    There is a new binding providers API to extend the default data binding mechanism. It acts as a general extensibility mechanism.
  • Throttling
    It is now possible to limit how often change events are fired (e.g. only one change event per 500ms). BTW, ko.dependentObservable has been renamed to ko.computed.

For a full list of all new features see Steve Sanderson’s blog entry.

There is also a Grails Plugin available, but as Knockout is just a single JavaScript-File, I would recommend to include it in a Grails project directly without a plugin.

Short URL for this post:
This entry was posted in Groovy and Grails, Java Web Frameworks and tagged , , , , , . Bookmark the permalink.

1 Response to Knockout JS 2.0.0 released – Dynamic JavaScript-UIs using Data Binding

  1. Pingback: Using a JavaScript Resource in a Grails Groovy Server Page | CorkeTech

Leave a Reply

Your email address will not be published. Required fields are marked *