Is it possible to change the style (using the "style" or "css" binding) of the selection list select item when using the "options" binding in the selection list? Or can this be done only using the "foreach" in the list of choices and style changes for each?
I have this in code:
<select id="components-select" size="4" name="components-select"
data-bind=" options: combinedComponents,
optionsText: 'displayName',
optionsValue: 'id',
value: chosenComponent"></select>
but if I add style: {color: isDefault() === true ? 'black' : 'red'}, then the whole list will be colored red if it isDefaultreturns false.
This is the only way to achieve this, in order to encode it as follows:
<select id="components-select" size="4" name="components-select"
data-bind="foreach: combinedComponents">
<option data-bind="value: id, text: displayName, style: {color: isDefault() === true ? 'black' : 'red'}"></option>
</select>
Or is there some form of Knockout.js magic that I don't know about?
Thank!
source
share