I have an observable array of objects
question = {
        ownerUserName: item.id,
        text: item.text,
        dataType: item.dataType,
        personalized: item.personalized,
        status: item.status,
        actionUserName: item.actionUserName
    }
And a select with options from this array:
<select id="questId" style="width: 425px" data-bind="options: questionList, optionsText: 'text'">
How with the help of knockout can I make so that if question.personalized == "Y" color of the text of this question would be green?
You can use foreach instead of usual options binding. Something like
<style>
   .highlighted{
      background-color: red;
   }
</style
<select id="questId" style="width: 425px" data-bind="foreach: questionList">
   <option data-bind="text: text, class: {highlighted: personalized == 'Y'}">
</select>
                        Your best bet is the css binding
A quick adaptation of the documentation to your need would be
<div data-bind="text: personalized, css: personalizedStatus">
   Profit Information
</div>
<script type="text/javascript">
    question.personalizedStatus = ko.computed(function() {
        return this.personalized() == "Y" ? "green" : "red";
    }, question);
</script>
<style>
    .green {color:green;}
    .red{color:red;}
</style>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With