[英]Filter ng-repeat in Angular
我在Google中搜索了很多內容,但沒有發現任何問題。 我的問題是如何過濾菜單選項值? 我將整個代碼放在下面的位置。
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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.