Javascript 角度成像条件

Javascript 角度成像条件,javascript,json,angularjs,Javascript,Json,Angularjs,基本上,我现在正在做的是调用一个jsonp数组,其中包含一个图标的图像url,该图标工作正常,除了图标外,显示正常。我想做的是用我自己的图标替换图标,但问题是它们是动态的,因为它是一个天气api,所以当天气变化时图标链接将更改为不同的图标。我能从json中得到的是天气的状态,例如部分多云,并用它来调用特定的img。我该如何处理这件事呢 var app=angular.module('app'); app.controller('MainCtrl', function($scope, $htt

基本上,我现在正在做的是调用一个jsonp数组,其中包含一个图标的图像url,该图标工作正常,除了图标外,显示正常。我想做的是用我自己的图标替换图标,但问题是它们是动态的,因为它是一个天气api,所以当天气变化时图标链接将更改为不同的图标。我能从json中得到的是天气的状态,例如部分多云,并用它来调用特定的img。我该如何处理这件事呢

 var app=angular.module('app');

app.controller('MainCtrl', function($scope, $http) {


    $http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/conditions/q/Australia/Melbourne.json?callback=JSON_CALLBACK').success(function(data){

     $scope.currentMelbourne=data;



  });
   $http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/conditions/q/Australia/Sydney.json?callback=JSON_CALLBACK').success(function(data){

     $scope.currentSydney=data;



  });

    $http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/conditions/q/Australia/Adelaide.json?callback=JSON_CALLBACK').success(function(data){

     $scope.currentAdelaide=data;



  });
    $http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/conditions/q/Australia/Darwin.json?callback=JSON_CALLBACK').success(function(data){

     $scope.currentDarwin=data;



  });

     $http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/conditions/q/Australia/Perth.json?callback=JSON_CALLBACK').success(function(data){

     $scope.currentPerth=data;



  });

    $http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/conditions/q/Australia/Cairns.json?callback=JSON_CALLBACK').success(function(data){

    $scope.currentCairns=data;



  });


  $http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/conditions/q/Australia/Brisbane.json?callback=JSON_CALLBACK').success(function(data){


     $scope.currentBrisbane=data;
     $scope.cityData=[
     {  name:'Brisbane',
        temp:$scope.currentBrisbane.current_observation.temp_c,  
        image:$scope.currentBrisbane.current_observation.icon
        },               

      { name:'Melbourne',
         temp:$scope.currentMelbourne.current_observation.temp_c,
          image:$scope.currentMelbourne.current_observation.icon

        },

     { 
        name:'Adelaide',
        temp:$scope.currentAdelaide.current_observation.temp_c ,  
        image:$scope.currentAdelaide.current_observation.icon


      },

     {  name:'Darwin',
         temp:$scope.currentDarwin.current_observation.temp_c  ,
        image:$scope.currentDarwin.current_observation.icon


      },

     {  name:'Perth',
         temp:$scope.currentPerth.current_observation.temp_c  ,
        image:$scope.currentPerth.current_observation.icon


     },

     {  name:'Cairns',

       temp:$scope.currentCairns.current_observation.temp_c,  
        image:$scope.currentCairns.current_observation.icon

    },
     ]




  }); 





});
这是html

<div id="weather-container">

        <div id="current-weather">
            <!--Angular JSON pull -->
            <div id="title"><span id="current-title">Current Weather</span></div>
            <div id="current-condition">{{currentSydney.current_observation.weather}}</div>
            <!--Image thingo here-->
             <img ng-src="{{currentSydney.current_observation.icon_url}}"></img>
            <div id="current-temp"><span id="current-temp"> {{currentSydney.current_observation.temp_c}} </span></div>
            <span id="current-city">{{currentSydney.current_observation.display_location.city}} </span>
        </div>






            <!--Angular JSON pull and iteration-->
        <div id="other-city-container">
            <div class="other-city-weather" ng-repeat="city in cityData" >
                <!--Image thingo here-->
             <img ng-src="{{city.image}}"></img>
            <div class="current-city-temp">
                <span>{{city.temp}}</span>
            </div>
            <div class="current-city-lower">
                <span>{{city.name}}</span>
            </div>
            </div>


        </div>


    </div>

当前天气
{{currentSydney.current_observation.weather}
{{currentSydney.current_observation.temp_c}
{{currentSydney.current_observation.display_location.city}
{{city.temp}}
{{city.name}

您可以编写一个helper
函数
,它将在每次成功的ajax请求后重写json中的url属性。请提供更多信息,以便我们能够帮助您

你想让我显示我的代码吗?图像区域返回一个字符串,它是天气的当前状态,例如多云