在我的反应ES6应用程序上,我需要执行以下操作: 获取某个组织的git hub成员列表,然后获取每个组织的信息详细信息。
代码:
handleDevelopers(res){
let lista = res.data.map(function(result) {
axios.get('https://api.github.com/users/'+result.login)
.then(function (response) {
console.log(response.data.name);
return <GitUser key={response.data.id} name={response.data.name}/>;
});
});
this.setState({
users: lista
});
}
componentWillMount() {
axios.get('https://api.github.com/orgs/:orgname/members')
.then((jsonRes) => this.handleDevelopers(jsonRes))
}
地图完成后如何设置setState?
答案 0 :(得分:1)
handleDevelopers(res){
let _self = this
axios.all(res.data.map(function(result) {
return axios.get('https://api.github.com/users/'+result.login)
.then(function (response) {
console.log(response.data.name);
return <GitUser key={response.data.id} name={response.data.name}/>;
});
})).then(function(lista){
_self.setState({
users: lista
});
}
componentWillMount() {
axios.get('https://api.github.com/orgs/:orgname/members')
.then((jsonRes) => this.handleDevelopers(jsonRes))
}