angularjs - Why is my custom filter predicate filter not working -


i have use case wherein have filter array based on selection 2 dropdowns. both selections md-select (from angular material) hence both selection array. record original array matches of record selection arrays should returned filter.

i have returned following logic, can't figure out why data not filtered.

$scope.filtertasks = function (t, i, array) {   if ($scope.filter.tradedir.length === 0 && $scope.filter.cluster.length === 0) {     return true;   }   else if ($scope.filter.tradedir.length !== 0 && $scope.filter.cluster.length === 0) {     $scope.filter.tradedir.foreach(function (td) {       if ((t.trade.code === td.trade.code) && (t.direction.code === td.direction.code)) {         return true;       }     });   } else if ($scope.filter.cluster.length !== 0 && $scope.filter.tradedir.length !== 0) {     $scope.filter.tradedir.foreach(function (td) {       if ((t.trade.code === td.trade.code) && (t.direction.code === td.direction.code)) {         $scope.filter.cluster.foreach(function(c) {           if (t.cluster.code === c.code) {             return true;           }         });       }     });   }   else {     return false;   } } 

surprisingly, when debug, can see control going till return statement each matched record. still, data not filtered. puzzled why?

below html code md-selects:

<div class="filter layout layout-sm-column task_top_filters">   <md-input-container ng-class="{'md-input-has-value': filter.tradedir}"                        class="flex-sm-100 md_container_fr_task">     <label>trade/direction</label>     <md-select multiple ng-model="filter.tradedir"                          md-on-close="closetradefilter(filter.tradedir)"                         ng-model-options="{trackby: '$value.name'}">       <md-option ng-value="t" ng-repeat="t in tradedirarray track $index">         {{t.name}}       </md-option>     </md-select>   </md-input-container>   <md-input-container  ng-disabled="filter.tradedir.length === 0"                        ng-class="{'md-input-has-value': filter.cluster}"                        class="flex-sm-100 md_container_fr_task">     <label>cluster</label>     <md-select multiple ng-model="filter.cluster"                          ng-model-options="{trackby: '$value.code'}">       <md-option ng-value="t" ng-repeat="t in filterclusters track $index">         {{t.code}}       </md-option>     </md-select>   </md-input-container> </div> 

and here how calling it:

<li ng-repeat="t in datalist| filter: filtertasks track t.id" class="li_row"> 

is there wrong filter? appreciated.

well, issue above code was returning true foreach function, instead should returned original filtertasks function. below code works fine:

$scope.filtertasks = function (t, i, array) {                 if ($scope.filter.tradedir.length === 0 && $scope.filter.cluster.length === 0) {                     return true;                 } else if ($scope.filter.tradedir.length !== 0 && $scope.filter.cluster.length === 0) {                     $scope.filter.tradedir.foreach(function (td) {                         if ((t.trade.code === td.trade.code) && (t.direction.code === td.direction.code)) {                             x = true;                         }                     });                     return x;                 } else if ($scope.filter.cluster.length !== 0 && $scope.filter.tradedir.length !== 0) {                     $scope.filter.tradedir.foreach(function (td) {                         if ((t.trade.code === td.trade.code) && (t.direction.code === td.direction.code)) {                             $scope.filter.cluster.foreach(function (c) {                                 if (t.cluster.code === c.code) {                                     x = true;                                 }                             });                             return x;                         }                     });                     return x;                 } else {                     return false;                 }             } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -