如何使用$ filter angular js过滤json中的内部数组(How to filter inner array in json using $filter angular js)

编程入门 行业动态 更新时间:2024-10-10 08:23:51
如何使用$ filter angular js过滤json中的内部数组(How to filter inner array in json using $filter angular js)

我想过滤json内部数组

这是我的阵列

{ "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"] },

我想按WFID = 1过滤

我试试这种方式

var saveWorkflowobj = $filter('filter')(tiggers.alltigger, { WFID: WorkFlowID});

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});

最满意答案

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> 
  
 

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> 
  
 

更多推荐

本文发布于:2023-08-06 11:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1449343.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   如何使用   filter   js   angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!