【发布时间】:2017-04-21 12:07:44
【问题描述】:
我有一个 Json 数据,我需要以角度创建嵌套过滤器搜索。如果你们能帮助我,因为我是新手,我试过了,但我发现有困难。
【问题讨论】:
-
你应该做一个小提琴
标签: angularjs json checkbox filter
我有一个 Json 数据,我需要以角度创建嵌套过滤器搜索。如果你们能帮助我,因为我是新手,我试过了,但我发现有困难。
【问题讨论】:
标签: angularjs json checkbox filter
我没有你的 css,但在高级别它应该像 THIS 和 multilevel 过滤器参考 THIS
单击复选框后,我将使用 addToFilter 函数将过滤器类别添加到我的数组之一。
HTML
<input type="checkbox" ng-checked="item.checked" ng-model="item.checked" ng-click="addToFilter(item.node.category)"/> {{ item.node.category }}
HTML
代码 filter:categoryFilter 将根据所选类别过滤数组中的记录。
<div ng-repeat="item in nodes | filter:categoryFilter | orderBy:'node.location' | groupBy:['node.location'] ">
<h2 ng-show="item.group_by_CHANGED">{{item.node.location}}</h2>
<ul>
<li>{{item.node.title}}</li>
</ul></div>
JS
此js代码是选中时从数组中添加所选类别,未选中时删除。
$scope.filtersApplied =[];
$scope.addToFilter = function(category)
{
var i = $.inArray(category.trim(), $scope.filtersApplied);
console.log(category);
if (i > -1) {
$scope.filtersApplied.splice(i, 1);
} else {
$scope.filtersApplied.push(category.trim());
}
}
$scope.categoryFilter = function(node) {
if ($scope.filtersApplied.length > 0) {
if ($.inArray(node.node.category.trim(), $scope.filtersApplied) < 0)
return;
}
return node;
}
** 请忽略我的分组代码。我只是想模拟你在图片中显示的内容。
使用 CSS 更新 SAMPLE
【讨论】: