js filter函数用法

filter筛选数组里面的对象筛选需要加一个if。不然就会变成操作而不是筛选,这里的返回是一个数组。里面存的是符合筛选条件的数组。

$scope.todos = [
                    {text:'测试1',done:true},
                    {text:'测试2',done:true}

                ];
count:function () {
        return          $scope.todos.filter(function (p1) {
                        if (!p1.done){
                        return p1

}}).length;
}

posted on 2017-04-07 10:36  fxxk院子  阅读(63)  评论(0)    收藏  举报

导航