[英]Axios array map callback
在我的 React 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)) }
地圖完成后如何設置狀態?
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.