2013-04-02 192 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 
    } 
];}