Knockout Switch-Case
Despite being a plugin that targets a single, specific use case, Knockout Switch-Case's popularity on GitHub is evidence that a switch/case control flow binding is a very useful tool. Instead of writing out a series of if
/ifnot
bindings, a single case-switch binding can be used:
<div data-bind="switch: orderStatus"> <div data-bind="case: 'shipped'"> Your order has been shipped. Your tracking number is <span data-bind="text: trackingNumber"></span>. </div> <div data-bind="case: 'pending'"> Your order is being processed. Please be patient. </div> <div data-bind="case: 'incomplete'"> Your order could not be processed. Please go back and complete the missing data. </div> <div data-bind="case: $default"> Please call customer service to determine the status of your order. </div> </div>
The preceding example can be seen in the cp8-case-switch...