2014-10-05 74 views
0

我有以下ARRY在我的範圍angularJs過濾器從控制器

items: [ 
{ 
id: "0", 
name: "כיבוי אורות", 
roomId: "0", 
type: "scenario", 
status: 1 
}, 
{ 
id: "1", 
name: "הדלקת אורות", 
roomId: "0", 
type: "scenario", 
status: 1 
}, 
{ 
id: "0", 
name: "תנור מטבח", 
roomId: "0", 
type: "heater", 
status: 0 
}] 

我想通過ID和類型的控制器內對其進行過濾(不NG-重複|過濾器)。

感謝配發

阿維

回答

1

好吧,如果你想通過姓名和身份證從控制器內篩選您可以只使用native filter。查看polyfill以支持舊版瀏覽器。

var type = "TypeTOfilter", id=idToFilter; 
$scope.items = items.filter(function(itm){ return itm.id === id && itm.type === type }); 

或者你甚至可以注入``$ filter`在你的控制器,如果你只是想這樣做一次,沒有它在NG-重複。

.controller('ctrl', ['$scope', 'filterFilter', function($scope, filter){ 
    //... 
    $scope.items = filter(items)({type:type, id:id}); 
    //.... 
}]); 

或者你甚至可以做一個for循環過濾掉的項目..

+0

感謝配發 阿維 – 2014-10-06 07:38:27