I would like to do it in Knockout.
<span class="badge" data-bind="text: rank, css: {'badge-success': firstPlace, 'badge-warning': !firstPlace}"></span>
Where my javascript model class has this method
self.firstPlace = ko.computed(function() { return self.rank() == 1; });
This prevents the creation of a warning icon class. I tried several access options in the data binding attribute, for example firstPlace == false and (!firstPlace) . Instead, I need to add a second inverse method to my model:
<span class="badge" data-bind="text: rank, css: {'badge-success': firstPlace, 'badge-warning': notFirstPlace}"></span>
Of course it works. And cheers for JS knockout, which is really very interesting to use. But that just seems wrong. Does anyone have a better method?
source share