【发布时间】:2016-11-17 13:19:24
【问题描述】:
UPD:如何在我的组件中显示数组元素 (WeatherCityName - h2)?可以看到加载了数组,但是当我点出属性时——出现错误,可能是语法有问题?
var WeatherBox = React.createClass({
handleWeatherSubmit: function(text) {
$.ajax({
url: this.props.url,
dataType: 'json',
type: 'POST',
data: 'cityName=' + text,
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
getInitialState: function() {
return {data: []};
},
render: function() {
return (
<div className="wetherBox">
<h1> Weather</h1>
<WeatherForm onWeatherSubmit={this.handleWeatherSubmit} />
<WeatherCityName data={this.state.data[0]} />
<WeatherList data={this.state.data} />
</div>
);
}
});
var WeatherCityName = React.createClass({
render: function(){
return(
<h2>{this.state.data[0].cityName}</h2>
);
}
});
【问题讨论】:
-
你想用
this.props(function(weatherItem) { ... });做什么?另外,将该 JSX 与 return 放在同一行。 -
我只尝试返回一次。
标签: javascript reactjs syntax