lundi 12 mars 2018

Angularjs checkbox filter on two arrays

I've been struggling to filter two different arrays, one with the checkbox values and another with whole data. In other terms, first array contains the field values from a sharepoint list and the second array contains the items from same sharepoint list. How can I filter based on the checkbox selected. Here is my code:

 <div ng-repeat="x in processes">
<input type="checkbox" ng-model="filteredData"/>
</div>
<div ng-repeat = "y in toBeFiltered | filter: {filteredData : true}">
<span class="title"></span>
<span class="process"> </span>
</div>

<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
  $scope.processes = [
    "Alfreds Futterkiste",
    "Berglunds snabbköp",
    "Centro comercial Moctezuma",
    "Ernst Handel",
  ];
  $scope.toBeFiltered = [{
  "Title": "title1",
  "process": "Alfreds Futterkiste"
  }, {"Title" : "title2",
  "process": "Alfreds Futterkiste, Berglunds Snabbkop"

  },{"Title" : "title2",
  "process": "Alfreds Futterkiste, Berglunds Snabbkop,Ernst Handel, 
  Centro Comercial Moctezuma"
  }];
});
</script>

I tried using ng-model, but that didn't work. Please help. Thanks!




Aucun commentaire:

Enregistrer un commentaire