-4

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.

Dss
  • 33
  • 7
  • Start with the [documentation](http://knockoutjs.com/documentation/options-binding.html) and then come back with a specific question if you are still having problems. – Matt Burland Jan 19 '16 at 17:59
  • hey i am able to display with simple array but not with the array of object...please help me – Dss Jan 19 '16 at 18:01
  • Look at example 3 in the documentation. It's a drop-down with javascript objects. – Matt Burland Jan 19 '16 at 18:02
  • Matt i am really not able to get it can you please simplify for me please..Actually i stored the data in array..now it became the array of objects..i am not able to iterate and display values – Dss Jan 19 '16 at 18:08
  • Since *nobody* can see any of your code, how do you expect anybody to simplify? Include the *relevant* bits of your code *in the question* – Matt Burland Jan 19 '16 at 18:11
  • If i open my array of objects my data is like: description: "Document Request" formatMessage: "" key: "" requestMessage: "" serviceCharge: "" subjectMessage: "" value: "DR" – Dss Jan 19 '16 at 18:12
  • I want a drop down of text as Document Request and the vale of DR – Dss Jan 19 '16 at 18:14

1 Answers1

4
<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.

Thomasov
  • 81
  • 4