2

在我的 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))
	}

地图完成后如何设置状态?

4

1 回答 1

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))
}
于 2015-12-21T23:22:48.697 回答