0

I want to filter json inner array

this is my array

{
    "code": "project_create",
    "WFID": ["1, "5", "2", "8", "9", "10", "7"]
 },
 {
   "code": "Task_create",
   "WFID": ["1", "5", "2", "8", "9"]
 },
 {
   "code": "project_update",
   "WFID": ["10", "5", "2", "8", "9"]
 },

I want to filter by WFID=1

I try this way

var saveWorkflowobj = $filter('filter')(tiggers.alltigger, { WFID: WorkFlowID});
5
  • Can you make sure if WorkFlowID is of type string? Commented Jul 5, 2017 at 5:00
  • yes its string type Commented Jul 5, 2017 at 5:01
  • 1
    what is tiggers.alltigger? provide more info or create a fiddle Commented Jul 5, 2017 at 5:24
  • what kind of output you want ?, if WFID = 1 that return the entire object of WFID = 1. Commented Jul 5, 2017 at 6:02
  • yes I want that output, Commented Jul 5, 2017 at 6:20

1 Answer 1

1

angular.module('app', []).controller('ctrl', ['$scope', '$filter', function($scope, $filter) {
    $scope.items = [
       {
          "code": "project_create",
          "WFID": ["1", "5", "2", "8", "9", "10", "7"]
       },
       {
         "code": "Task_create",
         "WFID": ["1", "5", "2", "8", "9"]
       },
       {
         "code": "project_update",
         "WFID": ["10", "5", "2", "8", "9"]
       }
    ];
 
    $scope.result = $filter('filter')($scope.items, {WFID : "1"}, function(a, b){
      return a === b;
    }); 
}])
<script src="//code.angularjs.org/snapshot/angular.min.js"></script>
 
 <div ng-app='app' ng-controller='ctrl'>   
   <ul>
     <li ng-repeat='item in result'>{{item | json}}</li>
   </ul>   
 </div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.