In my ViewModel I have the following method that returns me the css class depending on pState:
function MyViewModel()
{
var self = this;
self.GetClass = function(pState)
{
var lCssClass;
switch(pState)
{
case "warning":
lCssClass = 'bg-yellow';
break;
case "red":
lCssClass = 'font-red';
break;
default:
lCssClass = 'font-default';
break;
}
return lCssClass;
};
}
I want to add the class in my view:
<span class="list-item" data-bind="attr : { class : $root.GetClass('warning')}">This is a warning.</span>
My problem: the existing class list-item will be overridden.
Here is a fiddle: http://jsfiddle.net/d8L6v9h7/