0
HTML:基於國家選擇,需要填充國家和本市
<label for="country">Country *</label>
<select id="country" ng-model="statessource" ng-options="country for (country, states) in countries"
ng-change="GetSelectedCountry()">
<option value=''>Select</option>
</select>
<label for="state">State *</label>
<select id="state" ng-disabled="!statessource" ng-model="model.state" ng-options="state for (state,city) in statessource"
ng-change="GetSelectedState()"><option value=''>Select</option>
</select>
<label for="city">City *</label>
<select id="city" ng-disabled="!citiessource || !statessource" ng-model="city"><option value=''>
Select</option>
<option ng-repeat="city in citiessource" value='{{city}}'>{{city}}</option>
</select>
JS:
$scope.countries = {
'USA': {
'Alabama': ['Montgomery', 'Birmingham'],
'California': ['Sacramento', 'Fremont'],
'Illinois': ['Springfield', 'Chicago']
},
'India': {
'Maharashtra': ['Pune', 'Mumbai', 'Nagpur', 'Akola'],
'Madhya Pradesh': ['Indore', 'Bhopal', 'Jabalpur'],
'Rajasthan': ['Jaipur', 'Ajmer', 'Jodhpur']
},
'Australia': {
'New South Wales': ['Sydney'],
'Victoria': ['Melbourne']
}
};
$scope.GetSelectedCountry = function() {
$scope.strCountry = document.getElementById("country").value;
};
$scope.GetSelectedState = function() {
$scope.strState = document.getElementById("state").value;
};
我已經寫了上面JSON $ sope.countries填充根據國家州和城市。 我的國家和州的領域是完美的,但我的城市沒有任何物品。根據選定的國家填寫州和城市的任何其他解決方案也會有所幫助。
不錯的方法您的呼叫狀態! –
@ Angular_10,謝謝 –
感謝您的建議,其良好的解決方案。我的問題解決 –