angular.js - angularjs做級聯位址查詢ng-options點兩次才顯示為什麼
大家讲道理
大家讲道理 2017-05-15 17:05:51
0
2
516

在用angularjs做地址級聯選擇時,後台數據是已經發送拿到了,但點擊第一次時沒有顯示options,第二次才會顯示數據,

html:

<p class="w100 bs-bb clearfloat lh30 pt10 pb10p bb-gray" >
                    <!-- sel-provance -->
                    <span class="chooseaddress">省份</span>
                    <select class="w75 lh30 fr mr10p" ng-model="provincename" 
        ng-options="province.code as province.province_name for province in provinces" >
                        <option value="">省份</option>
                    </select><br>
                </p >
                <p class="w100 bs-bb clearfloat lh30 pt10 pb10p bb-gray">
                    <p>Province:{{provincename || 'None'}}</p>
                </p>
                <p class="w100 bs-bb clearfloat lh30 pt10 pb10p bb-gray"  ng-touchend="getCity()">
                    <span class="chooseaddress">市</span>
                    <select class="w75 lh30 fr mr10p" ng-model="cityname" 
                        ng-options="city.code as city.city_name for city in cities">
                        <option value="">市</option>
                    </select><br>
                    <!-- sel -->
                </p>
                <p class="w100 bs-bb clearfloat lh30 pt10 pb10p bb-gray">
                    <p>City:{{cityname || 'None'}}</p>
                </p>
                <p class="w100 bs-bb clearfloat lh30 pt10 pb10p bb-gray" ng-touchend="getArea()">
                    <!-- sel-area -->
                    <span class="chooseaddress">区/县</span>
                    <select class="w75 lh30 fr mr10p" ng-model="areaname"
                        ng-options="area.code as area.area_name for area in areas"></select><br>
                </p>
                

controller:

myApp.controller("newAddressCtrl", function($scope, $state, locals, shareFactory, addressService) {
        $scope.selfInfo = shareFactory.getVal("selfInfo");
        var token = locals.get('token', '');
        var proviceInfo = addressService.provinceService();
        proviceInfo.then(function(p) {
            $scope.provinces = p;
        }, function(p) {
            $scope.error = p;
        });
        
        $scope.requireValue = true;
        $scope.telPattern = new RegExp("^[1][358][0-9]{9}$");
        //点击获取对应的市

        $scope.getCity = function() {

            var cityInfo = addressService.cityService($scope.provincename);
            cityInfo.then(function(c) {

                $scope.cities = c.cities;

            }, function(c) {
                $scope.error = c;
            })

        }

        $scope.getArea = function() {
                var areaInfo = addressService.areaService($scope.cityname);
                areaInfo.then(function(a) {
                    $scope.areas = a.areas;
                }, function(a) {
                    $scope.error = a;
                })
            

        }
        $scope.back = function() {
            history.go(-1);
        }
        $scope.copyText = function() {
            var saveAddress = addressService.addressSaveService(id, $scope.contacter_name, $scope.provincename.province_id, $scope.cityname.city_id, $scope.areaname.area_id, $scope.postal_code, $scope.phone_number, $scope.detailed_address, token);
            saveAddress.then(function(d) {
                console.log(d);
            }, function(d) {
                $scope.error = d;
            })
        }
    })
    
    求助各位大神,请问是哪里的问题?我实在是找不到了T_T
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回覆(2)
Ty80

說關鍵問題啊,貼這麼多程式碼誰有時間看啊

滿天的星座

我想問一下,問題解決了?

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!