Simpleweather.js - 预测项目的图标

Simpleweather.js - icons for forecast items

我正在使用 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 的使用还很陌生。任何帮助将不胜感激。

forecast[X].image returns X 天条件下的全尺寸图像 url code.Hope 这就是你的意思伙计.. :)

$(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