Search code examples
knockout.jsknockout-2.0knockout-mapping-pluginknockout-validationknockout-mvc

Drop down from array of objects


Hi I am newbie in Knockout Js.Can anyone please explain me how can I create drop down from array of Objects.I want the text and the value of drop down should be different.And the objects are in Key Value Pair.

Thanks In Advance.


Solution

  • <select data-bind="options: nameOfOptionsCollection, optionsText: key, optionsValue: value, value: observable></select>
    

    http://knockoutjs.com/documentation/options-binding.html

    • options is where the array or object that you want to list in the dropdown will go
    • optionsText is the text in the dropdown
    • optionsValue will be the value attribute on the each option
    • value is the observable in your viewmodel that you want to bind to this dropdown

    Try to check http://knockoutjs.com when you have questions about knockout.