是否可以对布尔 ViewModel 属性的否定(“!")进行数据绑定? [英] Is it possible to data-bind visible to the negation ("!") of a boolean ViewModel property?
本文介绍了是否可以对布尔 ViewModel 属性的否定(“!")进行数据绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的 ViewModel 上使用一个属性来切换要显示的图标,而无需创建反向的单独计算属性.这可能吗?
I'd like to use a property on my ViewModel to toggle which icon to display without creating a separate computed property of the inverse. Is this possible?
<tbody data-bind="foreach: periods">
<tr>
<td>
<i class="icon-search" data-bind="visible: !charted, click: $parent.pie_it"></i>
<i class="icon-remove" data-bind="visible: charted, click: $parent.pie_it"></i>
</td>
</tr>
</tbody>
我的 ViewModel 有一个属性周期,它是一个月份数组,如下所示:
My ViewModel has a property periods which is an array of month, like this:
var month = function() {
this.charted = ko.observable(false);
};
推荐答案
在表达式中使用 observable 时,您需要将其作为函数访问,例如:
When using an observable in an expression you need to access it as a function like:
可见:!charted()
这篇关于是否可以对布尔 ViewModel 属性的否定(“!")进行数据绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文