This is a custom binding for using Selectize.js with your Knockout.js powered application.
Selectize is an HTML select alternative (like Select2, Chosen). Knockout is an MVVM framework for Javascript.
The custom binding can be used as:
<select data-bind="selectize: items, value: item_id, object: item"></select>
items is an array (or observable array) whereas item_id and item are observables. The dropdown is created with all objects from items.
This custom binding wraps the built-in options binding of Knockout.js. So, additional parameters like ‘optionsValue’, ‘optionsText’, ‘optionsCaption’, etc. can be used with this binding. See official documentation for further details. By default, the selectize binding uses id for optionsValue and name for optionsText.
By default, the text Choose... is used as optionsCaption. You can use optionsCaption: null for no captions (first item is selected by default).
The selectize binding provides optional object parameter. While the observable provided with value parameter (like item_id in our example) holds the id (or whatever property optionsValue defines), the observable provided with object parameter holds the whole item itself.
Your new post is loading...