如果 object.value == this,则 ng-repeat
If object.value == this, then ng-repeat
我有 3 个 table。每个代表具有不同角色的用户。这些适用于管理员、基本用户和所有用户。我想在我的 ng-repeat
或我的控制器中添加一个过滤器,以仅显示角色与我想要的相匹配的用户。这是我的对象:
{
"object": {
"users": [
{
"uuid": "19c5808b-0dcf-4b62-9c09-6caac1a5",
"fullname": "Brittani V",
"email": "brit@test.com",
"role": "root",
"last_log_in": 1427806300,
"deleted_at": null,
"active": true
},
{
"uuid": "b88415e9-a492-4206-83b4-5e7c42df",
"fullname": "Eric S.",
"email": "eric@test.com",
"role": "root",
"last_log_in": 1427817626,
"deleted_at": null,
"active": true
},
{
"uuid": "25649ad3-0e72-4946-b5bf-3484dcd2",
"fullname": "Joshua H.",
"email": "josh@test.com",
"role": "root",
"last_log_in": 1427813063,
"deleted_at": null,
"active": true
}
]
这是我的 table 类别名称 'Administrator'
<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>
使用ng-if
,或ng-hide
<tr ng-repeat="user in users" ng-if="user.role == 'root'">
我有 3 个 table。每个代表具有不同角色的用户。这些适用于管理员、基本用户和所有用户。我想在我的 ng-repeat
或我的控制器中添加一个过滤器,以仅显示角色与我想要的相匹配的用户。这是我的对象:
{
"object": {
"users": [
{
"uuid": "19c5808b-0dcf-4b62-9c09-6caac1a5",
"fullname": "Brittani V",
"email": "brit@test.com",
"role": "root",
"last_log_in": 1427806300,
"deleted_at": null,
"active": true
},
{
"uuid": "b88415e9-a492-4206-83b4-5e7c42df",
"fullname": "Eric S.",
"email": "eric@test.com",
"role": "root",
"last_log_in": 1427817626,
"deleted_at": null,
"active": true
},
{
"uuid": "25649ad3-0e72-4946-b5bf-3484dcd2",
"fullname": "Joshua H.",
"email": "josh@test.com",
"role": "root",
"last_log_in": 1427813063,
"deleted_at": null,
"active": true
}
]
这是我的 table 类别名称 'Administrator'
<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>
使用ng-if
,或ng-hide
<tr ng-repeat="user in users" ng-if="user.role == 'root'">