如何获取json子列表?

时间:2019-04-06 23:04:42

标签: javascript html arrays json object

我以js开头,我如何在其他列表中获取一个列表?我有,我不能在球员名单中显示元素

{
  "team1": {
    "name": "Origin",
    "players": 
[
      {
        "name": "A",
        "gold": 3324
      },
      {
        "name": "B",
        "gold": 9555
      },
      {
        "name": "C",
        "gold": 15463
      }
 ]
  },
    "team2": {
    "name": "G2",
    "players": 
[
      {
        "name": "D",
        "gold": 3324
      },
      {
        "name": "E",
        "gold": 9555
      },
      {
        "name": "F",
        "gold": 15463
      }
 ]
  }
}
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

</head>
<body>

<table id="heroesTable">
    <thead>

    </thead>
    <tbody id="match"></tbody>
</table>

<script>
    $.getJSON("ejemplo.json", function(data){
  $(data).each(function(i, match){
    $('#match').append($("<tr>")
      .append($("<td>").append(match.team1.name))
      .append($("<td>").append(match.team1.players.name))
      .append($("<td>").append(match.team1.players.gold))
      .append($("<td>").append(match.team2.name))
      .append($("<td>").append(match.team2.players.name))
      .append($("<td>").append(match.team2.players.gold)));
  });
    });
</script>
</body>
</html>

0 个答案:

没有答案