How to make ng-repeat filter out duplicate results

前端 未结 16 3012
鱼传尺愫
鱼传尺愫 2020-11-22 06:52

I\'m running a simple ng-repeat over a JSON file and want to get category names. There are about 100 objects, each belonging to a category - but there are only

16条回答
  •  眼角桃花
    2020-11-22 07:20

    If you want to list categories, I think you should explicitly state your intention in the view.

    
    

    in the controller:

    $scope.categories = $scope.places.reduce(function(sum, place) {
      if (sum.indexOf( place.category ) < 0) sum.push( place.category );
      return sum;
    }, []);
    

提交回复
热议问题