I have elements of the form:
{ number: 1, name: 'name1', selected:[100,400,210,103,102], ... },
{ number: 2, name: 'name2', selected:[100,400,210,104,102], ... },
{ number: 3, name: 'name3', selected:[100,103], ... }
(... are other string attributes)
My goal is to write an efficient angular filter to make filtering via the $ property possible while other I can also filter the selected array with the function of a contains filter.
Note that a named property will match properties on the same level only, while the special $ property will match properties on the same level or deeper. E.g. an array item like
{name: {first: 'John', last: 'Doe'}}will not be matched by{name: 'John'}, but will be matched by{$: 'John'}.
Filtering with the filter {$: 'name', selected[100,103]} should e.g. return the first and the third element above. Is it possible with simply writing a filter that will filter the selected (which I did) and chaining it with another filter? Or is it even possible without coding my own filter?
My Filter code basically is:
.filter('selectedFilter', function (underscore) {
return function (elements, filter) {
var result = [];
for (var idx in elements) {
var element = elements[idx];
if (underscore.intersection(element.selected, filter.selected).length === filter.selected.length) {
result.push(element[idx]);
}
}
return result;
}
}
I am using the filter like so:
<ion-item ng-repeat="element in vm.filtered = ( vm.filterElements(vm.searchFilter))
track by $index"></ion-item>
where
function filterElements (filter) {
var filteredElements = $filter('selectedFilter')(vm.elements, filter);
return filteredTrees;
}
$property anymore. Is that somehow possible with chaining?$property