无法从github api上获取total_count并显示

时间:2019-01-11 09:10:36

标签: reactjs redux github-api

  

我正在使用React Redux应用程序来获取github API。安慰   total_count其显示未定义。但是我可以显示   avatar_url,登录名,html_url。

     

下面是代码:

class SearchResults extends Component {

  renderList(user) {
    if (!user) {
      return <div class="panel">No User Available</div>
    }
    return user.items.map(item => {
      //  console.log(item);
      return <SearchItem
        key={item.id}
        name={item.login}
        src={item.avatar_url}
        alt={item.login}
        profileLink={item.html_url}
      />
    })
  }

  userCount() {
    let count = this.props.users.total_count;
    console.log(this.props.users.total_count);
    return <div className="panel"> {count} </div>;
  }

  render() {
    return (
      <div className="user-list">
        {
          this.userCount()
        }
        {
          this.props.users.map(this.renderList)
        }
      </div>
    )
  }
}

const mapStateToProps = ({ users }) => {
  return {
    users
  }
}

export default connect(mapStateToProps)(SearchResults);
  

以下是Github api示例:   {     “总数”:36252,     “ incomplete_results”:否,     “项目”:[       {         “ login”:“ abhi”,         “ id”:784144,         “ node_id”:“ MDQ6VXNlcjc4NDE0NA ==”,         “ avatar_url”:“ https://avatars2.githubusercontent.com/u/784144?v=4”,         “ gravatar_id”:“”,         “ url”:“ https://api.github.com/users/abhi”,         “ html_url”:“ https://github.com/abhi”,         “ followers_url”:“ https://api.github.com/users/abhi/followers”,         “ following_url”:“ https://api.github.com/users/abhi/following {/ other_user}”,         “ gists_url”:“ https://api.github.com/users/abhi/gists {/ gist_id}”,         “ starred_url”:“ https://api.github.com/users/abhi/starred {/ owner} {/ repo}”,         “ subscriptions_url”:“ https://api.github.com/users/abhi/subscriptions”,         “ organizations_url”:“ https://api.github.com/users/abhi/orgs”,         “ repos_url”:“ https://api.github.com/users/abhi/repos”,         “ events_url”:“ https://api.github.com/users/abhi/events {/ privacy}”,         “ received_events_url”:“ https://api.github.com/users/abhi/received_events”,         “ type”:“用户”,         “ site_admin”:否,         “得分”:123.63206       },       {...},    {..},   }

0 个答案:

没有答案