私はREST APIのJSONレスポンを持っています。私は、国、州、都市の価値を私のドロップダウンに移す必要があります。私のデフォルト値はALLです。私はこれらの国、州、都市の値をそれぞれデフォルトで最初の値としてALLとともにドロップダウンする必要があります。jsonレスポンスからドロップダウンリストへの値の表示
私の出力は[ALL , Delhi]
バンガロールがありません。
応答:
Geography : [{"countryname":"India","state":[{"statename":"Delhi",
"cities":[{"city":"Delhi"}]},{"statename":"Karnataka",
"cities":[{"city":"Bangalore"}]}]}]
HTML:
<form class="form-row " role="form">
<div class="form-group">
<label class="control-label col-sm-14" for="groupz">Country*</label>
<select class="form-control" ng-model="model.selectedCountry" name="country" ng-change="GetCountry(model.selectedCountry)">
<option ng-repeat=" item in model.countries track by $index" value="{{item}}">{{item}}</option>
</select>
</div>
<div class="form-group">
<label class="control-label col-sm-20" for="groupz">State*</label>
<select class="form-control" ng-model="model.selectedState" name="state" ng-change="GetState(model.selectedState)" ng-disabled="model.selectedCountry == 'ALL'">
<option ng-repeat="item in model.states track by $index" value="{{item}}">{{item}}</option> </select>
</div>
<div class="form-group">
<label class="control-label col-sm-20" for="groupz">City*</label>
<select class="form-control" ng-model="model.selectedCity" name="city" ng-change="GetCity(model.selectedCity)" ng-disabled="model.selectedState == 'ALL' || model.selectedCountry== 'ALL'">
<option ng-repeat="item in model.cities track by $index" value="{{item}}">{{item}}</option>
</select>
</div>
JS:
UserService.Geography(json).then(function(response) {
if (response.json.response.statuscode == 0 && response.json.response.statusmessage == 'Success') {
var geography = response.json.response.geography;
console.log("Geography : " + JSON.stringify(geography));
$scope.model.countries = [];
$scope.model.countries.push("ALL");
for (var i = 0; i < geography.length; i++) {
console.log(geography.length);
$scope.model.countries.push(geography[i].countryname);
console.log($scope.model.countries);
if (($scope.model.countries != []) || ($scope.model.countries != null)) {
console.log($scope.model.countries.length);
for (var j = 0; j < $scope.model.countries.length; j++) {
$scope.model.states = [];
$scope.model.states.push("ALL");
$scope.model.states.push(geography[i].state[i].statename);
console.log($scope.model.states);
if (($scope.model.states != []) || ($scope.model.states != null)) {
console.log($scope.model.states.length);
for (var k = 0; k < $scope.model.states.length; k++) {
$scope.model.cities = [];
$scope.model.cities.push("ALL");
$scope.model.cities.push(geography[i].state[i].cities[i].city);
console.log($scope.model.cities);
if (($scope.model.cities != []) || ($scope.model.cities != null)) {
$scope.model.segments = [];
var segments = "_ALL";
$scope.model.segments.push(segments);
console.log($scope.model.segments);
}
}
$scope.model.selectedCity = $scope.model.cities[0];
}
}
$scope.model.selectedState = $scope.model.states[0];
}
}
$scope.model.selectedCountry = $scope.model.countries[0];
}});
}
$scope.model.selectedCountry is the country selected by user in dropdown.
uはあなたがこんにちは、私はちょうど[ALL、デリー]ないバンガロールを取得しています –
直面しているどのような問題教えてくださいすることができ解決を願っています。 –