2

假设我有,

<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?这个怎么称呼。

http://jsfiddle.net/cPVGg/1/

4

1 回答 1

4

visible将您的绑定更改为:

<span data-bind="visible: $parent.checkVisibility($data)"></span>
于 2012-05-22T06:05:40.063 回答