`ng-repeat` 用于在数组中包含数组的下拉菜单
`ng-repeat` for a dropdown with an array inside of an array
想在下拉列表的 ng-repeat
中执行以下操作:
- 从JSON获取变量
product
categories
- 将
categories
数组分解为新行
- 过滤
unique
- 在下拉列表中显示
我在 Plunker 有一个演示,如您所见,我已经实现了过滤器,但我找不到打破数组并对其进行过滤的方法。
我的目标是制作一个包含 JSON 请求的过滤器,并制作一个包含可用类别的过滤器。
您不需要向控制器注入'angular.filter'
app.controller('MainCtrl', ['$scope', '$window', function($scope, $window) {
这里其实不需要filter,可以循环遍历categories,添加到数组中,如下所示
$scope.filtered = [];
angular.forEach($scope.products, function(key, value) {
angular.forEach(key.categories, function(key, value) {
if (!$scope.filtered.includes(key)) {
$scope.filtered.push(key);
}
})
})
想在下拉列表的 ng-repeat
中执行以下操作:
- 从JSON获取变量
product
categories
- 将
categories
数组分解为新行 - 过滤
unique
- 在下拉列表中显示
我在 Plunker 有一个演示,如您所见,我已经实现了过滤器,但我找不到打破数组并对其进行过滤的方法。
我的目标是制作一个包含 JSON 请求的过滤器,并制作一个包含可用类别的过滤器。
您不需要向控制器注入'angular.filter'
app.controller('MainCtrl', ['$scope', '$window', function($scope, $window) {
这里其实不需要filter,可以循环遍历categories,添加到数组中,如下所示
$scope.filtered = [];
angular.forEach($scope.products, function(key, value) {
angular.forEach(key.categories, function(key, value) {
if (!$scope.filtered.includes(key)) {
$scope.filtered.push(key);
}
})
})