2015-02-05 2 views
-1

Я успешно представляю обновления погоды с помощью simpleweather.js и пытаюсь получить значки прогноза, которые появятся рядом с днем ​​прогноза.Simpleweather.js - значки для прогнозируемых объектов

Использование:

$(document).ready(function() { 
    $.simpleWeather({ 
    location: 'Melborune, Australia', 
    unit: 'c', 
    success: function(weather) { 
    html = '<h2><i class="icon-'+weather.code+'"></i>'+weather.temp+'&deg;'+weather.units.temp+'</h2>'; 
    html += '<ul><li><i style="color:#000" class="icon-'+weather.code+'"></i>'+weather.city+', '+weather.region+'</li>'; 
    html += '<li class="currently">'+weather.currently+'</li>'; 
    html += '<li>'+weather.alt.temp+'&deg;C</li></ul>'; 

    for(var i=0;i<weather.forecast.length;i++) { 
    html += '<p><i style="color:#000" class="icon-'+weather.code+'"></i>'+weather.forecast[i].day+': '+weather.forecast[i].high+'</p>'; 
    } 

    $("#weather").html(html); 
    }, 
    error: function(error) { 
     $("#weather").html('<p>'+error+'</p>'); 
    } 
    }); 
}); 

я могу передвигаться, и он будет отображаться значком для текущей температуры, но я не знаю, что код значка для прогнозируемых дней.

Прошу прощения, я очень новичок в использовании API. Любая помощь будет принята с благодарностью.

ответ

1

forecast[X].image возвращает полный размер URL изображения для состояния code.Hope X дня этого я, что ты имел в виду мат .. :)

$(document).ready(function() { 
    $.simpleWeather({ 
     location: 'Melborune, Australia', 
     unit: 'c', 
     success: function (weather) { 
      html = '<h2><i class="icon-' + weather.code + '"></i>' + weather.temp + '&deg;' + weather.units.temp + '</h2>'; 
      html += '<ul><li><i style="color:#000" class="icon-' + weather.code + '"></i>' + weather.city + ', ' + weather.region + '</li>'; 
      html += '<li class="currently">' + weather.currently + '</li>'; 
      html += '<li>' + weather.alt.temp + '&deg;C</li></ul>'; 

      for (var i = 0; i < weather.forecast.length; i++) { 
       img = '<img style="float:left;" width="125px" src="' + weather.forecast[i].image + '">'; 
       html += '<p>' + img + '<i style="color:#000" class="icon-' + weather.code + '"></i>' + weather.forecast[i].day + ': ' + weather.forecast[i].high + '</p>'; 
      } 

      $("#weather").html(html); 
     }, 
     error: function (error) { 
      $("#weather").html('<p>' + error + '</p>'); 
     } 
    }); 
}); 

Fiddle here

+0

Именно то, что я был после того, как, благодаря кучки .. Я весь день ломаю голову. – mobius2000

Смежные вопросы