在过滤器中重复 Angular
Filter ng-repeat in Angular
我在 google 中搜索了很多,但没有找到适合我的问题。我的问题是如何过滤我的菜单选项值?我已将我的全部代码放在下面的位置。
http://plnkr.co/edit/q5WLaIvTN434o4nZNBdR
我有一个 CSS 菜单,它有 href
link 但它位于不同的 div
。那么如何根据菜单选择过滤我的结果呢?请帮助我。
我的搜索框也隐藏在菜单下方。我试着给它z-index
。但它不起作用。如何解决这个问题?
我的菜单div
如下:
<div id="menu-button">Menu</div>
<ul style="display:block;">
<li><a href='#' ng-click="menuFilter={}">Home</a></li>
<li id="deptMenu">
<a href='#'>Department</a>
<ul style="display: block;">
<li ng-repeat="dept in empDetails | unique:'department'">
<a href="" ng-click="menuFilter={department:'{{dept.department}}'}">{{dept.department}}</a>
</li>
</ul>
</li>
</ul>
</div>
但是容器在不同的位置如下:
<div class="container">
<div id="userlist" class="row">
<p data-ng-show="(empDetails | filter:searchTxt).length==0"><font color="red">There are no results for this search</font></p>
<div id="userDiv{{$index}}" class="shadow col-sm-1" ng-repeat="info in empDetails | filter:menuFilter | orderBy:'Name' | filter:searchTxt" tweenmax-animating-directive ng-click="openDetail()">
<div class="employeeDetail">
<div style="line-height:25px">
<b>{{info.Name}}</b><br/>
<b>number :</b>{{info.number}}<br/>
<b>Post :</b>{{info.post}}<br/>
</div>
</div>
</div>
</div>
</div>
我放置了 "menuFilter" 但它不起作用。
只需保存所选部门的值并在过滤器中使用它。因此,您的链接将更改为:
<a href="" ng-click="selectDepartment(dept.department)">{{dept.department}}</a>
$scope
获取新字段、过滤器和方法:
$scope.selectedDepartment = null;
$scope.departmentFilter = function (info) {
return !$scope.selectedDepartment || info.department === $scope.selectedDepartment;
};
$scope.selectDepartment = function (dept) {
$scope.selectedDepartment = dept;
};
并且 ng-repeat
更改为:
ng-repeat="info in empDetails | filter: departmentFilter | orderBy:'Name' | filter:searchTxt"
您还可以查看此版本:http://plnkr.co/edit/CKdAnwB6Muh1j3ohkgFq
在您的菜单中:
<a href="" ng-click="setDept(dept)">{{dept.department}}</a>
在你的控制器中:
$scope.showDept = false;
$scope.dept = {};
$scope.setDept = function(d) {
$scope.dept = d;
$scope.showDept = true;
};
并且在您的主容器中:
<div class="container">
<div id="userlist" class="row">
<p data-ng-show="(empDetails | filter:searchTxt).length==0"><font color="red">There are no results for this search</font></p>
<div id="userDiv{{$index}}" ng-show="showDept" class="shadow col-sm-1" tweenmax-animating-directive ng-click="openDetail()">
<div class="employeeDetail">
<div style="line-height:25px">
<b>{{dept.Name}}</b><br/>
<b>number :</b>{{dept.number}}<br/>
<b>Post :</b>{{dept.post}}<br/>
</div>
</div>
</div>
</div>
</div>
我在 google 中搜索了很多,但没有找到适合我的问题。我的问题是如何过滤我的菜单选项值?我已将我的全部代码放在下面的位置。
http://plnkr.co/edit/q5WLaIvTN434o4nZNBdR
我有一个 CSS 菜单,它有 href
link 但它位于不同的 div
。那么如何根据菜单选择过滤我的结果呢?请帮助我。
我的搜索框也隐藏在菜单下方。我试着给它z-index
。但它不起作用。如何解决这个问题?
我的菜单div
如下:
<div id="menu-button">Menu</div>
<ul style="display:block;">
<li><a href='#' ng-click="menuFilter={}">Home</a></li>
<li id="deptMenu">
<a href='#'>Department</a>
<ul style="display: block;">
<li ng-repeat="dept in empDetails | unique:'department'">
<a href="" ng-click="menuFilter={department:'{{dept.department}}'}">{{dept.department}}</a>
</li>
</ul>
</li>
</ul>
</div>
但是容器在不同的位置如下:
<div class="container">
<div id="userlist" class="row">
<p data-ng-show="(empDetails | filter:searchTxt).length==0"><font color="red">There are no results for this search</font></p>
<div id="userDiv{{$index}}" class="shadow col-sm-1" ng-repeat="info in empDetails | filter:menuFilter | orderBy:'Name' | filter:searchTxt" tweenmax-animating-directive ng-click="openDetail()">
<div class="employeeDetail">
<div style="line-height:25px">
<b>{{info.Name}}</b><br/>
<b>number :</b>{{info.number}}<br/>
<b>Post :</b>{{info.post}}<br/>
</div>
</div>
</div>
</div>
</div>
我放置了 "menuFilter" 但它不起作用。
只需保存所选部门的值并在过滤器中使用它。因此,您的链接将更改为:
<a href="" ng-click="selectDepartment(dept.department)">{{dept.department}}</a>
$scope
获取新字段、过滤器和方法:
$scope.selectedDepartment = null;
$scope.departmentFilter = function (info) {
return !$scope.selectedDepartment || info.department === $scope.selectedDepartment;
};
$scope.selectDepartment = function (dept) {
$scope.selectedDepartment = dept;
};
并且 ng-repeat
更改为:
ng-repeat="info in empDetails | filter: departmentFilter | orderBy:'Name' | filter:searchTxt"
您还可以查看此版本:http://plnkr.co/edit/CKdAnwB6Muh1j3ohkgFq 在您的菜单中:
<a href="" ng-click="setDept(dept)">{{dept.department}}</a>
在你的控制器中:
$scope.showDept = false;
$scope.dept = {};
$scope.setDept = function(d) {
$scope.dept = d;
$scope.showDept = true;
};
并且在您的主容器中:
<div class="container">
<div id="userlist" class="row">
<p data-ng-show="(empDetails | filter:searchTxt).length==0"><font color="red">There are no results for this search</font></p>
<div id="userDiv{{$index}}" ng-show="showDept" class="shadow col-sm-1" tweenmax-animating-directive ng-click="openDetail()">
<div class="employeeDetail">
<div style="line-height:25px">
<b>{{dept.Name}}</b><br/>
<b>number :</b>{{dept.number}}<br/>
<b>Post :</b>{{dept.post}}<br/>
</div>
</div>
</div>
</div>
</div>