KnockoutJS CSS绑定!= true [英] KnockoutJS css binding != true
问题描述
我的视图模型返回一个 true 值,并且我试图获取模板以相应地添加CSS.问题是,我找不到!= true的语法.
My view model is returning a true value, and I'm trying to get my template to add CSS accordingly. The problem is, I can't find the syntax for a != true.
我有这样的东西:
<div data-bind="css: {'lw-touched': checked, 'lw-touch': !checked}"></div>
我想说的是,如果选中=== true,则应用'lw-touched';如果选中=== false,则应用'lw-touch'.但这不起作用:(.所以我尝试了这个:
Which I thought would say, apply 'lw-touched' if checked === true, apply 'lw-touch' if checked === false. But that doesn't work :(. So I tried this:
<div data-bind="css: {'lw-touched': checked, 'lw-touch': checked !== true}"></div>
那也没用.
我敢肯定有办法做到这一点!我暂时找不到它.
I'm sure there is a way to do this! I just can't find it at the moment.
推荐答案
30秒后,我发布并解决了问题:(.
I posted and solved it 30 seconds later :(.
我要离开这是因为其他人可能也有同样的问题.
I'm leaving it because someone else might have this same problem.
data-bind="css: {'lw-touched': checked, 'lw-touch': !checked()}">
由于@MikaelÖstberg,我也使用了更好的语法
Also I used the better syntax thanks to @MikaelÖstberg
我将其标记为答案,这样我就不会得到更多的负面反馈了:/
I'm marking this as the answer so that I don't get more negative feedback :/
这篇关于KnockoutJS CSS绑定!= true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!