数据未填充在来自Angular js中的REST的JSON响应中

时间:2017-02-10 18:13:31

标签: angularjs json angularjs-directive angularjs-scope

我从一个像这样的WebService获取JSON值

  

“电”:

     

{“selectedElectricityBoard”:“ABCD”,

     

“electrictyConsumerNumber”: “12345”,

     

“isElectricityBoardChecked”:true

     

}

我从JSON数据生成了一个下拉列表,之后我选择了值并提交了值,该值从我的UI成功提交,现在案例是我正在编辑我所用的相同表单我做了一个Web服务调用,它返回了我从UI中选择的相同值,但所选值没有被填充/反映在下拉菜单中,任何建议或帮助都会非常明显,我的UI在Angular JS,代码片段如下:

      <div class="col-xs-2 no-padding ">
      <label>Consumer No.:</label>
      </div>
      <div class="col-xs-3">
       <span ng-hide="true" class="form-control" ng-required="true"
        close-text="Close">
       </span>
     <div class="group-3-text-boxes col-xs-3 no-padding" style="min-width: 100px;">
     <input type="text" name="consumer_number"
 ng-disabled="!form_data[selectedTab].electricity.isElectricityBoardChecked"
 ng-model="form_data[selectedTab].electricity.electrictyConsumerNumber"
 class="input-field"
ng-class="{true:'invalid-field',false:''}
 form_data[selectedTab].electricity.isElectricityBoardChecked &&   form_data[selectedTab].invalid.electricity]" required />

1 个答案:

答案 0 :(得分:1)

<html ng-app="app" ng-controller="ctrl">
<select id="state" ng-model="states" ng-options="state for (state,states) in total_states">
    <option value=''>Select State</option>
</select>
<select id="district" ng-model="districts" ng-options="district for (district,districts) in states">
    <option value=''>Select District</option>
</select>
<select id="city" ng-model="cities" ng-options="cities for cities in districts">
    <option value=''>Select City</option>
</select>
<br>
<br>
<br>

State ::  {{states}}
<br>
<br>
<br>
District:: {{districts}}
<br>
<br>
<br>
City ::  {{cities}}
控制器

app.controller('ctrl',ctrl);
ctrl.$inject=['$scope'];
function ctrl($scope) {
    $scope.total_states = {
        'Andhra Pradesh': {
            'Prakasam': ['Ongole', 'Chirala', 'Mrakapuram'],
            'Krishna': ['Vijayawada', 'Machalipatnam'],
            'Guntur': ['Guntur', 'Tenali', 'Bapatla']
        },
        'Telangana': {
            'Hyderabad': ['Hyderabad'],
            'Warangal': ['Wrangal', 'Hanmkonda'],
            'Khammam': ['Khmammam', 'Badrachalam']
        }
    };

}

试试这个有用......