2015-12-21 64 views
1

在我反应器ES6的应用程序,我需要做如下: 得到一些机构的混帐中枢成员的名单,并在其后得到每个人的信息的详细内容。爱可信阵图回调

代码:

handleDevelopers(res){ 
 
\t \t let lista = res.data.map(function(result) { 
 
\t  \t axios.get('https://api.github.com/users/'+result.login) 
 
\t  \t .then(function (response) { 
 
\t  \t \t console.log(response.data.name); 
 
\t  \t \t return <GitUser key={response.data.id} name={response.data.name}/>; 
 
\t  \t }); 
 

 
\t   
 
\t  }); 
 

 
\t  this.setState({ 
 
\t   users: lista 
 
\t  }); 
 
\t } 
 

 
\t componentWillMount() { 
 
\t \t axios.get('https://api.github.com/orgs/:orgname/members') 
 
\t  .then((jsonRes) => this.handleDevelopers(jsonRes)) 
 
\t }

我怎样才能SETSTATE地图完成后?

回答

-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)) 
}