Search code examples
javascriptcssknockout.jsoracle-jet

Apply dynamic css styles to drop down list items in Oracle jet


Here is my drop down list

<select id="productselect" aria-label="Single Select"      
        data-bind="ojComponent: {component: 'ojSelect', disabled: false,
                  value: productValue,optionChange: onChangeProduct,
                  rootAttributes: {style:'max-width:20em'}}">
   <!-- ko foreach: products -->
      <option data-bind="value:value, text:label, css:{labelclass:true}">   
      </option>    
   <!-- /ko -->
</select>

I would like to apply different colors to each list item by passing dynamic class, but not working. Please help.

Drop-down should be like

<option style = "color : red" data-bind="value:value, text:label">
<option style = "color : blue" data-bind="value:value, text:label">
and so on...

How to achieve this type of drop-down dynamically.


Solution

  • css binding is not working for above type of select component. I had to go with this type and it is working fine as expected.

    <ul id="prods" style="display: none" >
       <!-- ko foreach: prods -->
        <li data-bind="attr: {'oj-data-value': value}, style:
             {color:colorString}">
          <span data-bind="text: label"></span>
       </li>
      <!-- /ko -->
    </ul>
    <select id="prodselect" name="prod_names"
        data-bind="ojComponent: {component: 'ojSelect', disabled: true,
                   renderMode: 'jet',list: 'prods', value: product,
                   rootAttributes: {style:'max-width:100%'}}">
    </select>
    

    Passing required information from back end through 'prod' data structure.