Bells & Whistles for Knockout JS
Some ideas provided by this great post :
10 Knockout Binding Handlers I Don't Want To Live Without
Obviously.. there is more to come..
The following attributes bindings are added to Knockout.
- src
- href
- title
- alt
- width
- height
- placeholder
<img data-bind="src: mainVisual,
alt: description, title: description,
width: mainVisualWidth, height: mainVisualHeight">
This new binding provides a custom syntax to bind a ViewModel attribute to a class name amongst a list of known values.
<div class="product" data-bind="className: disponility[available|out-of-stock|pre-order]">
</div>
An even simpler binding that toggle a simple class name on a boolean value.
In its simplest form, the binding looks for an observable or property with the same name of the class that must be toggled.
<div class="product" data-bind="toggleClass: available">
</div>
In its slightly more sophisticated form, the binding looks for the name of the accessor between the [brackets] after the name of the class to toggle.
<div class="product" data-bind="toggleClass: available[inStock]">
</div>