我有一个充满父对象的数组,并且嵌套在每个父对象中我有一个包含子对象的数组。在不重建我的模型的情况下,我正在努力寻找使用 angular-ui-select 实现启用分组的下拉选择框的最佳方法。
$scope.allCategories = [
{
"code": "AAAA",
"name": "animals",
"categories": [
{
"code": "APET",
"name": "pets"
},
{
"code": "ASUP",
"name": "supplies"
},
{
"code": "AOTH",
"name": "other"
}
]
},
{
"code": "CCCC",
"name": "community",
"categories": [
{
"code": "CCNW",
"name": "classes and workshops"
},
{
"code": "COMM",
"name": "events"
},
{
"code": "CGRP",
"name": "groups"
}
]
}
]
这是我到目前为止所构建的,但我需要 angular-ui-select 具有的许多功能,而无需重新发明轮子。
<select class="form-control">
<optgroup ng-repeat="category in allCategories" label="{{category.name}}">
<option ng-repeat="childCategory in category.categories" value="{{childCategory.code}}">{{childCategory.name}}</option>
</optgroup>
</select>