AngularJS - 基于另一个选择

时间:2016-09-28 17:35:05

标签: angularjs json html-select

我是这个JSON:

{
    "world": [{
        "name": {
            "en": "America"
        },
        "type": "continent",
        "children": [{
            "type": "state",
            "name": {
                "en": "Florida"
            }
        }, {
            "type": "state",
            "name": {
                "en": "Hawaii"
            }
        }]
    }, {
        "name": {
            "en": "Europe"
        },
        "type": "continent",
        "children": [

        ]
    }]
}

我需要做两个选择。第一个包含类型"大陆"的选择,如果第一个孩子是>,则必须显示基于第一个的另一个。 0并包含状态选择。

1 个答案:

答案 0 :(得分:2)

你可以这样做,

 <select name="client" ng-model="selectedRequest.continent" ng-options="c.name.en for c in clients.world" required></select>
 <select id="department" ng-model="selectedRequest.state" ng-options="d.name.en for d in  selectedRequest.continent.children"></select>

DEMO

修改

Updated fiddle disabling select if children is empty