2013-04-02 157 views
0

试图为Angular.js过滤角重复

创建过滤器

Controller.js示例代码段:

function TitleListCtrl($scope) { 
    $scope.titles = [ 
    { "name": "Foobar", 
     "editions": 
     [{"print": true, 
      "ebook": false, 
      "audio": false }] 
    }, 
    { "name": "FooBarBar", 
     "editions": 
     [{"print": false, 
      "ebook": false, 
      "audio": false }] 
    } 
];} 

角HTML:

<ul ng-controller="TitleListCtrl"> 
     <li class="TitleList" ng-repeat="title in titles 
             | filter:isUpcoming 
             | orderBy:'date'">{{title.name}}</li> 
</ul> 

现在,我试图返回只有那些没有活动版本的标题(没有版本数组的成员设置为true)。发现很难找到在线的例子做这样的事情......

$scope.isUpcoming = function(title) { 
return title.editions[0] & title.editions[1] & title.editions[2]===false; 
}; 

回答

0

取而代之的是上面的方法,我用数据-NG-显示:

<ul ng-controller="TitleListCtrl"> 
<li class="TitleList" data-ng-show="!(title.upcoming)" 
            ng-repeat="title in titles 
            | filter:query 
            | orderBy:'date'">{{title.name}}</li> 
</ul> 

,并增加了标题一双新"upcoming": true,需要的地方。

function TitleListCtrl($scope) { 
    $scope.titles = [ 
    { "name": "Foobar", 
    "editions": 
    [{"print": true, 
     "ebook": false, 
     "audio": false }] 
    }, 
    { "name": "FooBarBar", 
    "editions": 
    [{"print": false, 
     "ebook": false, 
     "audio": false }], 
    "upcoming": true 
    } 
];}