2

反応した ES6 アプリでは、次のことを行う必要があります。ある組織の git ハブ メンバーのリストを取得し、その後、それぞれの情報の詳細を取得します。

コード:

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を設定できますか?

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 に答える