1
比方說,我有一組產品的JSON數據。每個產品都有一個分配給它的類別。我怎麼能列出所有的類別,但只顯示每個類別一次。這是我目前有列出了所有類別,包括重複:在AngularJS中列出JSON數據中的唯一值
(function() {
var app = angular.module('store', []);
app.controller('StoreController', ['$scope', function($scope) {
var vm = this;
$scope.products = [{
"category": "Cat1",
"name": "Product1"
}, {
"category": "Cat1",
"name": "Product2"
}, {
"category": "Cat2",
"name": "Product3"
}, {
"category": "Cat3",
"name": "Product4"
}]
}]);
})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<html lang="en" ng-app="store">
<body ng-controller="StoreController as vm">
<div ng-repeat="product in products" class="category">
<button>{{product.category}}</button>
</div>
</body>
</html>
所以我想Cat1
只顯示一次。
這是一個好主意......有評論! – Aaron