AngularJS实现地址选择器

    xiaoxiao2021-03-25  57

     

    myApp.controller('searchRunsCtrl', function($scope, $http) { $http.get("/users/searchProvince") .success(function(response) { $scope.provinceArr = response; }); $scope.$watch('desPrivince',function(newV, oldV){ if(newV !== oldV){ $scope.desCity = $scope.desArea = null; $scope.cityArr = $scope.areaArr = []; var pro = { pro_id: newV }; $http({ method: 'POST', url: '/users/searchCity', data: $.param(pro), headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .success(function(response) { $scope.cityArr = response; }); } }); $scope.$watch('desCity',function(newV, oldV){ if(newV !== oldV){ $scope.desArea = null; $scope.areaArr = []; var city = { city_id: newV }; $http({ method: 'POST', url: '/users/searchArea', data: $.param(city), headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .success(function(response) { $scope.areaArr = response; }); } }); $scope.search = function() { if($scope.desArea === undefined){ $scope.desFlag = true; } else{ var time = document.getElementById('calender').value; if(time){ $scope.searchDate = String(time); //YYYY-MM-DD HH:MM:SS } else { $scope.searchDate = (new Date()).Format("yyyy-MM-dd hh:mm:ss"); //YYYY-MM-DD HH:MM:SS } var classParams = { city_id: $scope.desArea, time: $scope.searchDate, date: (new Date(time)).Format('yyyyMMdd'), } $http({ method: 'POST', url: '/users/time', data: $.param(classParams), headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .success(function(response) { window.location.href = "/#/runsDetail/?date=" + classParams.date + "&city_id=" + classParams.city_id; }); } } });

     

    转载请注明原文地址: https://ju.6miu.com/read-38402.html

    最新回复(0)