如何迭代和呈现我的获取结果反应本机JSX

时间:2017-01-29 20:11:06

标签: react-native jsx

{
  "status": true,
  "live_score_domestic": [
    {
      "nTournamentID": "1",
      "cTournamentName": "sample tournament.",
      "cTournamentType": "D",
      "dStartDate": "2016-12-10",
      "dEndDate": "2016-12-12",
      "matches": [
        {
          "cVenueCode": "TTAB",
          "cTableName": "Table 1",
          "cEventType": "Junior Boys",
          "cMatchNo": "5",
          "cRound": "First Round",
          "nScheduledDate": "2016-12-11",
          "nScheduledTime": "11:45:00",
          "teamname1": "MOTHER SCHOOL",
          "teamname2": "HARI SHEWA SCHOOL",
          "nVenueID": "1",
          "nTableID": "1",
          "nTeamID1": "3",
          "nTeamID2": "4",
          "nTournamentID": "1",
          "nFixtureDetailsID": "15",
          "nEventTypeID": "5",
          "image": "http://example.com/tt.png"
        },
        {
          "cVenueCode": "TTAB",
          "cTableName": "Table 1",
          "cEventType": "Junior Boys",
          "cMatchNo": "4",
          "cRound": "First Round",
          "nScheduledDate": "2016-12-11",
          "nScheduledTime": "11:30:00",
          "teamname1": "MOTHER SCHOOL",
          "teamname2": "HARI SHEWA SCHOOL",
          "nVenueID": "1",
          "nTableID": "1",
          "nTeamID1": "3",
          "nTeamID2": "4",
          "nTournamentID": "1",
          "nFixtureDetailsID": "14",
          "nEventTypeID": "5",
          "image": "http://example.com/tt.png"
        }
      ]
    }
  ],
  "live_score_international": [
    {
      "nTournamentID": "2",
      "cTournamentName": "International Tournament Sample",
      "cTournamentType": "I",
      "dStartDate": "2016-12-22",
      "dEndDate": "2016-12-24",
      "matches": []
    }
  ],
  "results_domestic": [
    {
      "nTournamentID": "1",
      "cTournamentName": "sample tournament.",
      "cTournamentType": "D",
      "dStartDate": "2016-12-10",
      "dEndDate": "2016-12-12",
      "matches": [
        {
          "cVenueCode": "TTAB",
          "cTableName": "Table 1",
          "cEventType": "Junior Boys",
          "cMatchNo": "5",
          "cRound": "First Round",
          "nScheduledDate": "2016-12-11",
          "nScheduledTime": "11:45:00",
          "teamname1": "MOTHER SCHOOL",
          "teamname2": "HARI SHEWA SCHOOL",
          "nVenueID": "1",
          "nTableID": "1",
          "nTeamID1": "3",
          "nTeamID2": "4",
          "nTournamentID": "1",
          "nFixtureDetailsID": "15",
          "nEventTypeID": "5",
          "image": "http://example.com/tt.png"
        },
        {
          "cVenueCode": "TTAB",
          "cTableName": "Table 1",
          "cEventType": "Junior Boys",
          "cMatchNo": "4",
          "cRound": "First Round",
          "nScheduledDate": "2016-12-11",
          "nScheduledTime": "11:30:00",
          "teamname1": "MOTHER SCHOOL",
          "teamname2": "HARI SHEWA SCHOOL",
          "nVenueID": "1",
          "nTableID": "1",
          "nTeamID1": "3",
          "nTeamID2": "4",
          "nTournamentID": "1",
          "nFixtureDetailsID": "14",
          "nEventTypeID": "5",
          "image": "http://example.com/tt.png"
        }
      ]
    }
  ],
  "results_international": [
    {
      "nTournamentID": "2",
      "cTournamentName": "International Tournament Sample",
      "cTournamentType": "I",
      "dStartDate": "2016-12-22",
      "dEndDate": "2016-12-24",
      "matches": []
    }
  ],
  "fixture_point_domestic": [
    {
      "nTournamentID": "1",
      "cTournamentName": "sample tournament.",
      "cTournamentType": "D",
      "dStartDate": "2016-12-10",
      "dEndDate": "2016-12-12"
    }
  ],
  "fixture_point_international": [
    {
      "nTournamentID": "2",
      "cTournamentName": "International Tournament Sample",
      "cTournamentType": "I",
      "dStartDate": "2016-12-22",
      "dEndDate": "2016-12-24"
    }
  ]
}

这是获取结果。我想首先渲染像国内锦标赛这样的标题。然后我想在国内循环播放。然后在每场锦标赛中进行所有比赛。我怎么做到这一点?任何人提前帮助。谢谢:)

你可以帮我弄清楚如何迭代所有

3 个答案:

答案 0 :(得分:0)

首先,您应该决定如何在屏幕上显示数据。它们是否可点击,是否可以滚动,是否应该采用屏幕的哪个部分等等。根据未来应用程序的视觉设计,您可以选择确切的反应原生视觉组件将代表屏幕上的数据。最好的方式。

例如,如果它适用于您的应用程序的可视化设计,您可以查看react-native ListViewScrollView组件,以呈现相同复杂数据的无穷无尽的列表。

答案 1 :(得分:0)

如果迭代整个JSON对象是你的意图,那么一个简单的方法是for ... in循环。

例如:

var obj = {a: 1, b: 2, c: {a: 1, b: 2}};
function walk(obj) {
  for (var key in obj) {
    if (obj.hasOwnProperty(key)) {
      var val = obj[key];
      console.log(val);
      walk(val);
    }
  }
}
walk(obj);

取自:iterating through json object javascript

答案 2 :(得分:0)

def listBuckets(config: Config, bucketName: String): Unit = {
    val accessKey = "85eb40dxxxxx"
    val secretKey = "xxxxxxxxxxxx"
    val endPoint = "https://v01.my.company.net:8080"
    val credentials = new BasicAWSCredentials(accessKey, secretKey);
    val clientConfig = new ClientConfiguration();
    clientConfig.setProtocol(Protocol.HTTPS);
    val client = AmazonS3ClientBuilder.standard()
       .withCredentials(newAWSStaticCredentialsProvider(credentials))
       .withClientConfiguration(clientConfig)
       .withPathStyleAccessEnabled(true)
       .withEndpointConfiguration(new EndpointConfiguration(endPoint, "us-east-1"))
       .build();
    System.out.println(client.listBuckets())
}

这将使用对象属性(live_score_domestic,live_score_international等)来遍历最顶层的数据。然后你可以使用data [key]来获取它的内容。