How to conditionally render a css class with knock

2019-03-17 13:41发布

I have some html like the following:

<div class="control-group">
    <input type="text" data-bind="value: $data.DealCode" name="DealCode" class="input-mini" />
</div>

However, ifnot: $data.DealCodeIsValid, I need to render the following:

<div class="control-group error">
    <input type="text" data-bind="value: $data.DealCode" name="DealCode" class="input-mini" />
</div>

Note the additional class "error" in the div. Is there a way to do that with knockoutjs?

标签: knockout.js
1条回答
Evening l夕情丶
2楼-- · 2019-03-17 13:55

Something like

<div data-bind="css: {'control-group': true, error: (!$data.DealCodeIsValid)}">

Check here for more info

查看更多
登录 后发表回答