我有这个(简化的)数据:
[{
"Id": "1",
"Name": "Option (WITHOUT SubValues) - should be selectable",
"SubValues": []
},
{
"Id": "2",
"Name": "Option (WITH SubValues)",
"SubValues": [{
"Id": "2-1",
"Name": "SubValue - should be selectable"
},
{
"Id": "2-2",
"Name": "SubValue2 - should be selectable"
}
]
}]
使用ng-options:
<div ng-app="myApp">
<div ng-controller="myController">
<div class="col-md-4">
<div class="form-group">
<select ng-model="myType" class="form-control" ng-options="item.Id as item.Name for item in data.d">
</select>
</div>
</div>
</div>
</div>
我需要的是:
SubValues
- 应该可以选择。SubValues
- 那应该成为
&#39; optgroup
&#39;并且可以选择SubValue。可能是这样的:
<select ng-model="myType" class="form-control" ng-options="item.Id as item.SubValues[1].Name group by item.Name for item in data.d">
这里的Fiddle希望能让它更清晰。
目前的结构有可能吗?如果没有,最好的方法是什么?