我想说,
<ul data-bind="foreach: items">
<li>
<span data-bind="text: name"></span>
<span data-bind="visible: $parent.checkVisiblity"></span>
</li>
</ul>
和
var ViewModel = function() {
this.items = [{name: 'a'},{name: 'b'}];
this.checkVisiblity = function(item) {
console.log(item)
return item.name === 'a';
}
};
ko.applyBindings(new ViewModel());
为什么敲门不会调用函数checkVisiblity?怎么称呼它。
答案 0 :(得分:4)
将visible
绑定更改为:
<span data-bind="visible: $parent.checkVisibility($data)"></span>