如何在可靠的下拉中加载json?

时间:2017-02-09 14:03:09

标签: javascript angularjs

<b>Country:</b>
              &nbsp;
<select id="country" ng-model="statessource" ng-disabled="!type"  ng-options="country for (country, states) in countries" ng-change="GetSelectedCountry()">
                <option value=''>Select Country</option>    
            </select>
<b>State:</b>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <select id="state" ng-disabled="!statessource"  ng-model="citiessource"   ng-options="state for (state,city) in statessource"
            ng-change="GetSelectedState()"  >
                <option value=''>Select State</option>
            </select><br>
<b>City:</b>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <select  id="city" ng-disabled="!citiessource || !statessource" ng-model="codessource"  ng-options="city for (city,code) in citiessource" ng-change="GetSelectedCity()"><option value=''>SelectCity
                </option>
            </select><br>
<b>PostCode:&nbsp;</b> 
            <select id="code" ng-disabled="!citiessource || !statessource || !codessource" ng-model="code" ng-change="GetSelectedCode()">
            <option value=''>SelectZipCode
                <option ng-repeat="code in codessource" value='{{code}}'>{{code}}</option>
            </select>

  $scope.countries = {
            'USA': {
                    'IL': {'CHICAGO':['60633','60646','60653','60656','60607','60632','60643','60652','60620','60612','60661','60624','60634','60601','60827','60644','60631','60630','60617','60610','60659','60621','60647','60609','60616','60637','60655','60649','60602','60622','60642','60603','60629','60641','60619','60615','60640','60707','60654','60605','60623','60606','60614','60608','60604','60651','60638','60618','60611','60657','60613','60636','60639','60628','60625','60660','60645','60626']},
                    'CA': { 'SAN FRANCISCO':['94127','94115','94124','94131','94104','94103','94121','94188','94129','94122','94109','94134','94141','94144','94123','94110','94116','94158','94133','94105','94102','94112','94108','94111','94130','94117']},
                    'LA': { 'BATON ROUGE':['70812','70808','70806','70807','70805','70816','70810','70802','70819','70811','70809','70815','70820','70814','70801']},
                } 
        };

在这里,我正在手动传递值,正如您在&#34; $ scope.countries&#34;中看到的那样。在可靠的下降。我想通过json加载这些值。

我的json就像:

[{
    "country": "USA",
    "state": "CA",
    "city": "SAN FRANCISCO",
    "postcode": "94127"
}, {
    "country": "USA",
    "state": "CA",
    "city": "SAN FRANCISCO",
    "postcode": "94107"
}, {
    "country": "USA",
    "state": "NY",
    "city": "NEW YORK",
    "postcode": "10026"
}, {
    "country": "USA",
    "state": "NY",
    "city": "NEW YORK",
    "postcode": "10016"
}, {
    "country": "USA",
    "state": "CA",
    "city": "SAN FRANCISCO",
    "postcode": "94115"
}, {
    "country": "USA",
    "state": "NY",
    "city": "NEW YORK",
    "postcode": "10009"
}, {
    "country": "USA",
    "state": "IL",
    "city": "CHICAGO",
    "postcode": "60623"
}, {
    "country": "USA",
    "state": "CA",
    "city": "SAN FRANCISCO",
    "postcode": "94124"
}, {
    "country": "USA",
    "state": "IL",
    "city": "CHICAGO",
    "postcode": "60606"
}, {
    "country": "USA",
    "state": "CA",
    "city": "SAN FRANCISCO",
    "postcode": "94131"
}, {
    "country": "USA",
    "state": "LA",
    "city": "BATON ROUGE",
    "postcode": "70812"
}, {
    "country": "USA",
    "state": "IL",
    "city": "CHICAGO",
    "postcode": "60614"
}, {
    "country": "USA",
    "state": "NY",
    "city": "BRONX",
    "postcode": "10461"
}, {
    "country": "USA",
    "state": "NY",
    "city": "BROOKLYN",
    "postcode": "11221"
}, {
    "country": "USA",
    "state": "IL",
    "city": "CHICAGO",
    "postcode": "60608"
}, {
    "country": "USA",
    "state": "NY",
    "city": "NEW YORK",
    "postcode": "10003"
}, {
    "country": "USA",
    "state": "IL",
    "city": "CHICAGO",
    "postcode": "60604"
}, {
    "country": "USA",
    "state": "IL",
    "city": "CHICAGO",
    "postcode": "60651"
},
}]

请建议我该怎么做。

0 个答案:

没有答案