是否可以对布尔型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);
};
推荐答案
在表达式中使用可观察对象时,您需要使用如下函数来访问它:
When using an observable in an expression you need to access it as a function like:
visible: !charted()
这篇关于是否可以对布尔型ViewModel属性的取反(“!")进行可见的数据绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文