2016-11-16 72 views
0

下面的代碼應根據所選擇的狀態顯示的用戶列表中, JSP代碼濾波器不表現爲預期狀態= 「ACTIVE」

<table> 
    <thead> 
     <tr> 
     <th>Aggregate</th> 
     <th>User id</th> 
     <th>First Name</th> 
     <th>Last Name</th> 
     <th>Phone Number</th> 
     <th>Email</th> 
     <th class="text-center">Status</th> 
     </tr> 
    </thead> 

    <tbody > 

     <tr> 
      <td><input type="text" class="form-control" ng-model="search.agId" /></td> 
      <td><input type="text" class="form-control" ng-model="search.id" /></td> 
      <td><input type="text" class="form-control" ng-model="search.firstName" /></td> 
      <td><input type="text" class="form-control" ng-model="search.lastName" /></td> 
      <td><input type="text" class="form-control" ng-model="search.mobileNo" /></td> 
      <td><input type="text" class="form-control" ng-model="search.emailId" /></td> 
      <td> 
       <select class="form-control" ng-model="search.status"> 
        <option value=""> Select </option> 
        <option value="ACTIVE"> Active </option> 
        <option value="INACTIVE"> In Active </option> 
        <option value="B"> Blocked </option> 
       </select> 
      </td> 
     </tr> 


     <tr ng-repeat="userone in filtereddata = (users.data | filter:search)"> 
      <td>{{ userone.agId }}</td> 
      <td>{{ userone.id }}</td> 
      <td>{{ userone.firstName }}</td> 
      <td>{{ userone.lastName }}</td> 
      <td>{{ userone.mobileNo }}</td> 
      <td>{{ userone.emailId }}</td> 
      <td class="text-center" ng-switch on="userone.status"> 
       <span class="inac label label-success" ng-switch-when="ACTIVE">Active</span> 
       <span class="inac label label-danger" ng-switch-when="INACTIVE">In Active</span> 
       <span class="inac label label-danger" ng-switch-when="B">Blocked</span> 
      </td> 
     </tr> 

    </tbody> 
</table> 

控制器JS代碼

$scope.$watch('search', function (newVal, oldVal) { 
      $scope.filtered = filterFilter($scope.users.data, newVal); 

      console.log($scope.filtered); 

      $scope.bigTotalItems = (typeof $scope.filtered == 'undefined') ? 0 : $scope.filtered.length; 
      $scope.noOfPages = Math.ceil($scope.bigTotalItems/$scope.entryLimit); 
      $scope.currentPage = 1; 
     }, true); 

它適用於INACTIVE和阻止(即B)用戶選擇 ACTIVE其顯示

我在控制器JS代碼 給出一個簡單的​​的活動和非活動狀態的所有用戶來說,它實際上是在選擇返回活動和非活動成員過濾後的數據裏面活動。它適用於其他選擇。

我應該如何解決這個問題?

讓我知道是否需要任何額外的數據

+0

此問題被錯誤標記爲'java'標記。我已經刪除了這個標籤。 – AlexR

回答

1

angular.module('test', []).controller('Test', Test); 
 

 
function Test($scope, $filter) { 
 
    $scope.data = [{ 
 
    name: 'apple', 
 
    status: 'inactive' 
 
    }, { 
 
    name: 'banana', 
 
    status: 'active' 
 
    }, { 
 
    name: 'grape', 
 
    status: 'deleted' 
 
    }, { 
 
    name: 'orange', 
 
    status: 'inactive' 
 
    }, { 
 
    name: 'pear', 
 
    status: 'deleted' 
 
    }, { 
 
    name: 'watermelon', 
 
    status: 'active' 
 
    }] 
 
    
 
    $scope.filter = function(actual, expected) { 
 
    if (expected == '') return true; 
 
    
 
    return angular.equals(actual, expected); 
 
    } 
 
    
 
    $scope.$watch('search', function(newVal) { 
 
    $scope.filtered = $filter('filter')($scope.data, newVal, $scope.filter); 
 
    }); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script> 
 
<div ng-app='test' ng-controller='Test'> 
 
    Search: 
 
    <select ng-model="search"> 
 
    <option value="">Select</option> 
 
    <option value="active">Active</option> 
 
    <option value="inactive">Inactive</option> 
 
    <option value="deleted">Deleted</option> 
 
    </select> 
 
    <hr> 
 
    <div ng-repeat="item in data | filter:search:filter"> 
 
    {{item.name}} - {{item.status}} 
 
    </div> 
 
    <hr> 
 
    <div ng-repeat="item in filtered"> 
 
    {{item.name}} - {{item.status}} 
 
    </div> 
 
</div>

通過閱讀API reference,它看起來像你可以在第三個參數傳遞true執行嚴格的比較。

<tr ng-repeat="userone in filtereddata = (users.data | filter:search:true)">

如果您需要正確的結果在你的控制器,你需要在第三個參數傳遞也是如此。

$scope.filtered = filterFilter($scope.users.data, newVal, $scope.filter);

編輯:要選擇空濾器時解決空的結果的問題,我們需要使用自定義過濾功能。更新的代碼。

+0

即使經過上述變更,問題仍然存在 – abhi314

+0

@abhi314包含代碼示例 – Icycool

+0

在上面的代碼片段中選擇任何狀態,然後選擇'選擇'狀態,然後顯示完整列表,但它是空的。 – abhi314