访问api数据块

时间:2016-10-04 16:09:57

标签: api reactjs

我正在摆弄反应天气应用程序以获得乐趣,而且我无法访问数据块。

api请求返回以下内容:

"hourly": {
    "summary": "Rain throughout the day.",
    "icon": "rain",
    "data": [
        {
            "time": 1453399200,
            "summary": "Rain",
            "icon": "rain",
            "precipIntensity": 0.1379,
            "precipProbability": 0.85,
            "precipType": "rain",
            "temperature": 48.16,
            "apparentTemperature": 46.41,
            "dewPoint": 46.89,
            "humidity": 0.95,
            "windSpeed": 4.47,
    ...
};

我目前的代码是

getInitialState: function() {
  return {
    forecast: '',
    hourly: '',
    hdata: []
  }
},

componentDidMount: function() {
  this.serverRequest = $.get(this.props.source, function (result) {
    var forecast = result[0];
    this.setState({
      forecast: result.currently,
      hourly: result.hourly,
      hdata: result.hourly.data
    });
  }.bind(this));
},

  componentWillUnmount: function() {
    this.serverRequest.abort();
  },

  render: function() {
    return (
      <div>
        <h1>Current weather</h1>
        <div>{this.state.forecast.icon}</div>
        <div>{this.state.forecast.temperature} F</div>
        <div>{this.state.forecast.summary}</div>
        <div>{this.state.forecast.windSpeed} m/s</div>
        <h1>Weather today</h1>
        <div>{this.state.hourly.icon}</div>
        <div>{this.state.hdata.temperature} F</div>
        <div>{this.state.hourly.summary}</div>
        <div>{this.state.hdata.windSpeed} m/s</div>
      </div>
    )
  }
});

我的问题是我没有得到hdata array的任何回复 剩下的就是工作 任何人都可以帮助我吗?

提前致谢

0 个答案:

没有答案