KnockoutJS Declarative selectedOptions Binding - KnockoutJS

What is KnockoutJS Declarative selectedOptions Binding?

KnockoutJS Declarative selectedOptions Binding is used to work with elements which are selected currently in multi list select form control. This binding can be used with option binding and <select> form control only.

When the user selects or de-selects an item in the multi-select list, this adds or removes the corresponding value to an array on your view model. Assueme if it is an Observable array then items selected or de-selected from UI are also updated in array in ViewModel thus making it a two-way binding method.

Syntax

Parameters

  • Parameter here will be an array (also can be Observable one). The active items from select element are stored into this array. Earlier items will be overwritten.
  • If the parameter is Observable array then items selected are updated as and when underlying observable is changed. Element is processed only once if no Observable array is used.

Example

Let us see below example which explains the use of selectedOptions Binding

Output

  • Let's carry out the below steps to see how the above code works:
  • Save the above code in selectedoptions-bind.htm file.
  • Open this HTML file in a browser.
  • selectedTutorials is an array to store selected options.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

KnockoutJS Topics