2016-05-17 100 views
0

我是新来的angularJs。我遇到了一个问题,我需要通过查找数组中的元素来过滤数组(在ng-repeat中)。如何通过在angularJs中查找数组中的元素来过滤数组?

<div class="row" ng-repeat="(class_list_key, class_list) in trialList | filter: {class_id:selected_class_option_arr}"> 

我试过上面的代码(这是错误的)。这里selected_class_option_arr是一个数组,其中有数值,我需要使用class_id来过滤trialList数组。

阵列selected_class_option_arr是这样的 -

["Sat_09:00_AM_10:30_AM", "Fri_10:00_AM_11:00_AM"] 

我试图找到,但没有得到适当的例子按我的要求。

回答

1

提供在NG-重复和循环通过对阵列的过滤器功能,以筛选出所需的值:

<div class="row" ng-repeat="classList in trialList | filter: filterClass > 

在控制器:

$scope.filterClass = function(classList) { 
     for(var i=0; i < selected_class_option_arr.length; i++) { 
      return classList.class_id.indexOf(selected_class_option_arr[i]) != -1 
    } 
}; 

工作Plunker:https://plnkr.co/edit/yQ7D9fwwitfMktOkGjF8?p=preview

+0

谢谢@ Dev-One,工作得很好 –