I am coding up a dropdown list using knockout.js:
views() is an array of Objects instantiated via JSON using REST. displayName is a String attribute of these objects and is not observable. I would like to compare the displayName attribute and if it matches a certain word, I would like to apply some style to that option.
<select id="views" data-bind="
options: views(),
optionsText: 'displayName',
optionsValues: 'id',
value: selectedView,
style: { color: ( displayName == 'some arbitrary text') ? 'red' : 'black' }
"></select>
The dropdown works as intended when I dont add the style binding to it. I can do a simple comparision (i.e. 1 == 1) and it works (although all the options turn red). What I want to do is to compare the 'displayName' attribute to some arbitrary text. It is just a string now, containing any text, but later on this string will be called from my ViewModel.
This will allow me to set certain options in different styles, if my view model requires them to be. Any ideas?