【发布时间】:2014-05-14 02:37:01
【问题描述】:
好的,我有一个 ng-repeat:
<div id="scrolltwo" class="animate-repeat panel" ng-repeat="items in arrayfull |filter:filtertype ">
在过滤器类型中我有:
[[0] => "Typeone", [1] => "Typetwo" ]
如何让过滤器遍历整个数组并匹配与值匹配的结果?
使用自定义过滤器更新:
<div id="scrolltwo" class="animate-repeat panel" ng-repeat="items in arrayfull | array | filter:matchaccnttypes(accnttypes)">
有效的数组过滤器:
.filter('array', function() {
return function(items) {
console.log(items);
var filtered = [];
angular.forEach(items, function(item) {
filtered.push(item);
});
return filtered;
};
})
匹配不匹配的帐户类型!:
$scope.matchaccnttypes = function matchaccnttypes(query) {
return function(items) {
return items.Organtype.match(query);
angular.forEach($scope.accnttypes, function(value, key){
console.log(key + ': ' + value);
});
}
};
它只返回传递给 $scope.accntypes 数组的最后一个值,这是我上面的示例数组..
【问题讨论】:
-
您的意思是如果一个项目与数组中的 一个 值匹配则通过?还是全部?
-
数组中的一个值..
-
如果您的 arrayfull = [1,2,3,4] 和 filtertype =[1,2] 。你期待的结果是什么?
-
我希望结果是 NEWarrayfull = [1,2]
-
@marcKline 这就是我认为我已经完成了一半但失败了,我会在这里发布代码。
标签: javascript angularjs