Knockoutjs: how to add a header to parameters in select

I am using Knockoutjs options binding to populate the elements I select

<select data-bind="value: val, options: options, optionsText: 'text', optionsValue: 'ID'"> </select> 

But for some options, the text is the same. Then I would like to add a title attribute to add information. Can I do this with a knockout without changing the knockout itself?

A function in optionsText can be used, but I don't see how

+4
source share
1 answer

You can do this using foreach binding, for example:

 <select data-bind="foreach: options, value: selectedValue"> <option data-bind="value: ID, text: text, attr: {title: title}" ></option> </select> 

Here is a working example.

+5
source

Source: https://habr.com/ru/post/1437861/


All Articles