如何通过查找 angularJs 数组中的元素来过滤数组?
How to filter an array by finding elemets in array in angularJs?
我是 angularJs 的新手。我面临一个问题,我需要通过查找数组中的元素来过滤数组(在 ng-repeat 中)。
<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"]
我试图找到但没有找到符合我要求的合适示例。
在ng-repeat中提供一个过滤函数,循环遍历against数组,过滤出需要的值:
<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
我是 angularJs 的新手。我面临一个问题,我需要通过查找数组中的元素来过滤数组(在 ng-repeat 中)。
<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"]
我试图找到但没有找到符合我要求的合适示例。
在ng-repeat中提供一个过滤函数,循环遍历against数组,过滤出需要的值:
<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