javascript - Filtering data based on dynamic check box Categories in Angular JS? -
i'm trying achieve filter check box option dynamic data category , sub category.
how want is,
[] category [] sub category [] sub category [] category [] sub category [] sub category [] sub category ... , on
assume []
check box above.
here's sample json data :
[ { "category": { "name": "aaa - 1" }, "parentcategory": { "name": "aaa" }, "title" : "xxxxx", }, { "category": { "name": "aaa - 2" }, "parentcategory": { "name": "aaa" }, "title" : "yyyy", } ]
based upon above data, i'm trying want is,
sidebar :
[] aaa [] aaa - 1 [] aaa - 2
main content :
initially show title. after checked, show title related category/sub category.
note : pl don't think i'm asking without effort. i've seen examples in jsbin, couldn't find wanted achieve. btw i'm new angular.
if understand correctly want that: http://jsfiddle.net/ms403ly8/67/
firstly found first parent item json array. found parent's children , add it.
angular.foreach($scope.itemlist, function(itm) { var filtereditem = $filter('filter')($scope.itemlist, { parentcategory: itm.parentcategory.name}); if($filter('filter')($scope.parentitems, { name: itm.parentcategory.name}).length == 0){ $scope.parentitems.push({name: itm.parentcategory.name, children:filtereditem}); } });
Comments
Post a Comment