Class
CSS classes for HTML elements can be defined in a similar way to regular attributes. They can also be defined using a JSON object, where each property value is checked for Truthy. If a value is true, the corresponding class name is added.
This alternative definition method can bring convenience since defining classes is a common practice.
Here are some examples:
Vue code:
<div env="server">
<script>
var para = "text";
function checkactive(input) {
return input === "text";
}
</script>
<div :class="{ isActive: checkactive(para), otherclass: true, nomatch:checkactive('nomatch')}"></div>
</div>
Result:
<div>
<div class="isActive otherclass"></div>
</div>
k- Syntax
<div env="server">
<script>
var para = "text";
function checkactive(input) {
return input === "text";
}
</script>
<div k-attribute="class { isActive: checkactive(para), otherclass: true, nomatch:checkactive('nomatch')}"></div>
</div>