2016-09-28 105 views
0

我這個JSON:AngularJS - 選擇基於另外一個

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

     ] 
    }] 
} 

我需要做兩個選擇。第一個包含「大陸」類型的選擇,如果第一個子節點> 0且包含狀態選擇,則必須顯示基於第一個節點的另一個節點。

+0

什麼的一些JS?你的代碼在哪裏? – DMCISSOKHO

回答

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

+0

你的答案似乎很完美..如果沒有孩子,如何隱藏第二個選擇? – paolopolix

+0

使用ng-show並添加你的條件,標記爲答案,如果它有幫助 – Sajeetharan

+0

ng-show =「selectedRequest.continent.children> 0」對我不起作用 – paolopolix

相關問題