4

Hi Friends ici deux données dans un fichier JSON où je dois créer Sélectionnez l'option basée sur le champ pays et incluent des données basé sur le champ de localisationCréer sélection avec otpgroup à partir de deux données différentes

"countries": [ 
     { 
      "id": "75", 
      "country": "France" 
     }, 
     { 
      "id": "82", 
      "country": "Germany" 
     }, 
     { 
      "id": "208", 
      "country": "Switzerland" 
     }, 
     { 
      "id": "226", 
      "country": "United Kingdom" 
     }, 
     { 
      "id": "227", 
      "country": "United States" 
     } 
    ], 
    location": [ 
     { 
      "id": "49", 
      "name": "Aberdeen", 
      "country_id": "226", 
      "country": "United Kingdom" 
     }, 
     { 
      "id": "52", 
      "name": "All Cities", 
      "country_id": "226", 
      "country": "United Kingdom" 
     }, 
     { 
      "id": "51", 
      "name": "All Cities", 
      "country_id": "82", 
      "country": "Germany" 
     }, 
     { 
      "id": "50", 
      "name": "All Cities", 
      "country_id": "227", 
      "country": "United States" 
     } 
     { 
      "id": "31", 
      "name": "San Jose", 
      "country_id": "227", 
      "country": "United States" 
     }, 
     { 
      "id": "42", 
      "name": "Seattle", 
      "country_id": "227", 
      "country": "United States" 
     }, 
     { 
      "id": "18", 
      "name": "Stuttgart", 
      "country_id": "82", 
      "country": "Germany" 
     }, 
     { 
      "id": "41", 
      "name": "Washington DC", 
      "country_id": "227", 
      "country": "United States" 
     } 
    ], 

fichier HTML

<select ng-model="location"> 
       <optgroup ng-repeat="data in location" label="{{data.country}}"> 
        <option ng-repeat="item in data" value="{{data.country}}::{{item.name}}">{{item.name}}</option> 
       </optgroup> 
    </select> 

Je dois montrer mes données ressemblent à:

enter image description here

J'essaie le code ci-dessus mais je ne réussis pas. S'il vous plaît Aide

Répondre

2

Pas besoin d'utiliser un tableau différent, vous pouvez aussi le faire en utilisant uniquement tableau de localisation que suivre

<select ng-model="location" ng-options="option.name as option.name group by option.country for option in locations"></select> 

Check this working example

+0

Merci mon pote, tu vraiment sauvé la journée. – Neotrixs

+0

Vous êtes les bienvenus – jitender