0
我有简单的JSONReactJs呈现简单的JSON
{"id":157,"content":"Hello, World!"}
我想渲染ID在anotther一个DIV和内容。对我来说问题是当我打电话{this.state.data.content}
两次崩溃。
var Stuff = React.createClass({
getInitialState: function() {
return {
data: []
};
},
componentDidMount: function() {
$.ajax({
url: "http://rest-service.guides.spring.io/greeting",
dataType: 'json',
cache: false,
success: function(response) {
this.setState({
data: response
});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
render: function() {
return (
<div>Response - {this.state.data.content}</div>
);
}
});
你有没有[检查你的控制台](http://stackoverflow.com/documentation/javascript/185/hello-world/714/using-console-log)的错误? –
我不知道你在说什么 – TeodorKolev