描述没有定义

时间:2017-02-08 14:43:05

标签: javascript json ajax

我的代码是

    var data = JSON.parse(http.responseText);
        var weatherData = new Weather(cityName, data);
        weatherData.temperature = data.main.temp;
        updateWeather(weatherData);

    function Weather(cityName, data) {
    this.cityName = cityName
    data.weather[0].description = descriptions;
    this._temperature = '';
}

    function updateWeather(weatherData) {
    weatherCity.textContent = weatherData.cityName;
    weatherDescription.textContent = weatherData.descriptions;
    weatherTemperature.textContent = weatherData.temperature;

    loadingText.style.display = 'none';
    weather.style.display = 'block';
}

我得到错误描述没有定义。如果我这样做,工作正常

var data = JSON.parse(http.responseText);
        var weatherData = new Weather(cityName, data.weather[0].description);
        weatherData.temperature = data.main.temp;
        updateWeather(weatherData);

    function Weather(cityName, description) {
    this.cityName = cityName
    this.description = descriptions;
    this._temperature = '';
}

    function updateWeather(weatherData) {
    weatherCity.textContent = weatherData.cityName;
    weatherDescription.textContent = weatherData.descriptions;
    weatherTemperature.textContent = weatherData.temperature;

    loadingText.style.display = 'none';
    weather.style.display = 'block';
}

我不知道现在该做什么。我没有收到价值吗?有人可以解决它,所以我可以理解。我是新手,所以这可能是一个愚蠢的问题。试图以第一种方式做到这一点,因为我想要添加更多东西,如天气压力,风速,日出等。

2 个答案:

答案 0 :(得分:1)

下面的代码块中有拼写错误 -

function Weather(cityName, description) {
this.cityName = cityName
this.description = descriptions;
this._temperature = '';

请更正this.description = descriptionsthis.description = description

答案 1 :(得分:0)

这里

mvn spring-boot:run

你写了function Weather(cityName, description) { this.cityName = cityName this.description = descriptions; // <-- this._temperature = ''; } 而不是descriptions