无法访问获取React应用的嵌套JSON结果

时间:2019-08-20 02:59:05

标签: javascript json reactjs fetch

我真的很迷恋这个部分,我一直在开发react应用,当他们单击选项卡/按钮时,将获取更多结果以返回,并且我尝试通过它映射以显示。但始终显示未定义。

我在控制台中看到了结果,但是每次尝试访问结果时,它会返回空或错误private SelectList SetSelectedItemValue(SelectList source) { Category category = new Category(); SelectListItem firstItem = new SelectListItem(); int selectListCount = -1; if (source != null && source.Items != null) { System.Collections.IEnumerator cenum = source.Items.GetEnumerator(); while (cenum.MoveNext()) { if (selectListCount == -1) { selectListCount = 0; } selectListCount += 1; category = (Category)cenum.Current; source.SetSelectedValue(category.Name); break; } if (selectListCount > 0) { foreach (SelectListItem item in source.Items) { if (item.Value == cenum.Current.ToString()) { item.Selected = true; break; } } } } return source; }

Here's my full code

undefined

映射以显示:


componentDidMount() {
    const results = fetch("https://api.github.com/users")
      .then(res => {
        return res.json();
      })
      .then(data => {
        console.log("data", data);
        this.setState({ results: data });
      });
  }

  handleReferences = id => {
    console.log("handleReferences", id);
    const results = fetch(id)
      .then(res => {
        return res.json();
      })
      .then(data => {
        return this.setState({ repos: data });
      })
      .catch(err => console.log(err));
  };

JSON示例:

  {repos.map((repo, index) => {
          return (
            value === index && (
              <TabContainer key={repo.node_id}>
                <Typography variant="h6">Name: {repo.owner.login} </Typography>
                <Typography> Forks: {tag.forks} </Typography>
              </TabContainer>
            )
          );
        })}

非常感谢您!

0 个答案:

没有答案