[英]Axios array map callback
On my react ES6 app i need to do the follow: Get a list of git hub members of some organization and after it get the info details of each one.在我的 React ES6 应用程序上,我需要执行以下操作:获取某个组织的 git hub 成员列表,然后获取每个组织的信息详细信息。
The code:编码:
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)) }
How can i setState after map done?地图完成后如何设置状态?
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))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.