单个输出数据可以,如何循环输出接口中的数据?求解?
原始
<div id="demo"></div>
<script type="text/babel">
var UserGist = React.createClass({
getInitialState:function(){
return {
username: '',
lastGistUrl: ''
}
},
componentDidMount:function(){
$.get(this.props.source, function(result) {
var datas = result[0];
this.setState({
username: datas.owner.login,
lastGistUrl: datas.html_url
})
}.bind(this));
},
render:function(){
return (
<div>
<em>{this.state.username}</em> : {this.state.lastGistUrl}
</div>
)
}
});
ReactDOM.render(
<UserGist source="https://api.github.com/users/octocat/gists" />,
document.getElementById('demo')
);
</script>
成功
江户川乱折腾
相关分类