我在谷歌上搜索了很多,我没有找到我的问题。我的问题是如何过滤我的菜单选项值?我已经把我的整个代码放在下面的位置。
http://plnkr.co/edit/q5WLaIvTN434o4nZNBdR我有一个CSS菜单,其中有href
链接,但它位于不同的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/4vbvlsejZivio2A4seWa?p=info.
您也可以查看此版本: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>