如何使用knockout.js有条件地渲染一个css类 [英] How to conditionally render a css class with knockoutjs
本文介绍了如何使用knockout.js有条件地渲染一个css类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些类似以下的html:
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>
但是,ifnot: $data.DealCodeIsValid
,我需要渲染以下内容:
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>
请注意div中的附加类错误".有没有办法用基因敲除法做到这一点?
Note the additional class "error" in the div. Is there a way to do that with knockoutjs?
推荐答案
类似
<div data-bind="css: {'control-group': true, error: (!$data.DealCodeIsValid)}">
这篇关于如何使用knockout.js有条件地渲染一个css类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文