gpt4 book ai didi

checkbox - knockout js : Bind checkbox enable when boolean is false

转载 作者:行者123 更新时间:2023-12-02 06:04:36 25 4
gpt4 key购买 nike

我的每个元素都有 IsAnabled 和 IsDeafult。如果 IsDefault = true,则应禁用该复选框。

当我这样做时它会起作用,除了我想要“启用”的相反效果:

<input type="checkbox" data-bind="checked: IsEnabled, enable: IsDefault" />

我试过:

<input type="checkbox" data-bind="checked: IsEnabled, enable: !IsDefault" />
<input type="checkbox" data-bind="checked: IsEnabled, enable: IsDefault == 'false'" />
<input type="checkbox" data-bind="checked: IsEnabled, enable: IsDefault != 'true'" />
<input type="checkbox" data-bind="checked: IsEnabled, enable: IsDefault != true" />
<input type="checkbox" data-bind="checked: IsEnabled, enable: IsDefault == '0'" />

但仍然没有运气......

最佳答案

我建议您阅读以下文章:10 Things to Know About KnockoutJS引用文章:

Most bindings will call ko.utils.unwrapObservable on the value passed to it, which will safely return the value for both observables and non-observables. However, in a binding if you use an observable in an expression, then you need to reference it as a function. Likewise, in code you typically need to reference your observables as functions, unless you actually want to pass the observable itself (not the value).

所以当你在表达式中使用它们时,你应该将 () 添加到 observable 中:

<input type="checkbox" data-bind="checked: IsEnabled, enable: !IsDefault()" />

关于checkbox - knockout js : Bind checkbox enable when boolean is false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13159608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com