2015-03-31 51 views
0

我有3個表格。每個人都代表具有不同角色的用戶。這些適用於管理員,基本用戶和所有用戶。我想在我的ng-repeat或我的控制器中添加一個過濾器,以僅顯示角色與我想要的相匹配的用戶。這是我的目標:如果object.value == this,那麼ng-repeat

{ 
    "object": { 
    "users": [ 
     { 
     "uuid": "19c5808b-0dcf-4b62-9c09-6caac1a5", 
     "fullname": "Brittani V", 
     "email": "[email protected]", 
     "role": "root", 
     "last_log_in": 1427806300, 
     "deleted_at": null, 
     "active": true 
     }, 
     { 
     "uuid": "b88415e9-a492-4206-83b4-5e7c42df", 
     "fullname": "Eric S.", 
     "email": "[email protected]", 
     "role": "root", 
     "last_log_in": 1427817626, 
     "deleted_at": null, 
     "active": true 
     }, 
     { 
     "uuid": "25649ad3-0e72-4946-b5bf-3484dcd2", 
     "fullname": "Joshua H.", 
     "email": "[email protected]", 
     "role": "root", 
     "last_log_in": 1427813063, 
     "deleted_at": null, 
     "active": true 
     } 
    ] 

這裏是我的表, '管理員' 的類別名稱

<tab heading="Administrators"> 

       <table class="table table-hover members-table middle-align"> 
       <thead> 
        <tr> 
         <!-- <th></th> --> 
         <th>Name and Role</th> 
         <th class="hidden-xs hidden-sm">E-MAIL</th> 
         <th>Last Login<th> 
         <th></th> 
         <th></th> 
        </tr> 
       </thead> 
       <tbody> 
        <tr ng-repeat="user in users **if user's role == root** "> 
         <!-- <td class="user-cb"> 
          <input type="checkbox" class="cbr" name="members-list[]" value="1" checked /> 
         </td>--> 
         <td class="user-name"> 
          <a href="" class="name">{{user.fullname}}</a> 
          <span>{{user.role}}</span> 
         </td> 
         <td class="hidden-xs hidden-sm"> 
          <span class="email">{{user.email}}</span> 
         </td> 
         <td class="user-id"> 
          {{user.last_log_in}} 

         </td> 
         <td class="text-right"> 
          <a href="" class="edit"> 
           <span class="glyphicon glyphicon-pencil"></span> 
          </a> 
         </td> 
         <td class="text-right"> 
          <a href="" class="delete"> 
           <span class="glyphicon glyphicon-remove"></span> 

          </a> 
         </td> 
        </tr> 
       </tbody> 
      </table> 

     </tab> 
+0

我也試過這個' – JoshPMP 2015-03-31 19:51:20

回答

0

使用ng-if,或ng-hide

<tr ng-repeat="user in users" ng-if="user.role == 'root'"> 
+0

ng-if更好一些,它不會在DOM中。 – 2015-03-31 20:01:37

+0

工作感謝! – JoshPMP 2015-03-31 20:45:15