Angular JS:仅当 ng-repeat 有成员时才显示项目?
Angular JS: show item only if ng-repeat has members?
我有 json 数据,其中一系列 objects 有一个数组 "options"。有些项目在此数组中有项目,有些则没有,如
{
"label": "ORDERS",
"enabled": true,
"selected": true,
"options": [
{
"label": "Edit addresses",
"value": true
},
{
"label": "Cancel orders",
"value": true
},
{
"label": "Uncancel orders",
"value": false
}
]
},
{
"label": "FOO",
"enabled": true,
"selected": false,
"options": [
]
},
如您所见,ORDERS 有选项,但 FOO 没有。
这导致如下布局:
我有转发器数据之外的项目,允许 header 和复选框。
我只想在选项数组有项目时显示那些。这是我的布局方式:http://plnkr.co/edit/QLY9311r4nSCRUolKvLs?p=preview
我不知道如何使用 "Allowed" header 和没有选项数组的行上的复选框隐藏行:
这行得通吗?
<tr ng-if="t.options.length">
<td colspan="2"></td>
<td align="center">Allowed</td>
</tr>
<tr ng-if="t.options.length">
<td colspan="2"></td>
<td align="center">
<input type="checkbox" name="" id="" />
</td>
</tr>
<tr ng-repeat="o in t.options">
<td></td>
<td>{{o.label}}</td>
<td align="center">
<input type="checkbox" ng-model="o.selected" />
</td>
</tr>
我有 json 数据,其中一系列 objects 有一个数组 "options"。有些项目在此数组中有项目,有些则没有,如
{
"label": "ORDERS",
"enabled": true,
"selected": true,
"options": [
{
"label": "Edit addresses",
"value": true
},
{
"label": "Cancel orders",
"value": true
},
{
"label": "Uncancel orders",
"value": false
}
]
},
{
"label": "FOO",
"enabled": true,
"selected": false,
"options": [
]
},
如您所见,ORDERS 有选项,但 FOO 没有。
这导致如下布局:
我有转发器数据之外的项目,允许 header 和复选框。
我只想在选项数组有项目时显示那些。这是我的布局方式:http://plnkr.co/edit/QLY9311r4nSCRUolKvLs?p=preview
我不知道如何使用 "Allowed" header 和没有选项数组的行上的复选框隐藏行:
这行得通吗?
<tr ng-if="t.options.length">
<td colspan="2"></td>
<td align="center">Allowed</td>
</tr>
<tr ng-if="t.options.length">
<td colspan="2"></td>
<td align="center">
<input type="checkbox" name="" id="" />
</td>
</tr>
<tr ng-repeat="o in t.options">
<td></td>
<td>{{o.label}}</td>
<td align="center">
<input type="checkbox" ng-model="o.selected" />
</td>
</tr>