Rendering Complex Data from JSON file

Rendering Complex Data from JSON file

responsivelabsresponsivelabs Posts: 31Questions: 8Answers: 0

Ok, so this one has really got me stumped - Currently, I'm allowing a user to upload a JSON file into Datatables, and then I'm rendering the primary data in the columns, and additionally the more granular data I'm putting into a child row for each of the parent rows. The only thing is, some of the data for a particular data type within the JSON isn't explicitly stated. Take the following data for example:

{
  "id": "44a8ab7b-ce49-4fb2-8892-3c5d6ac43805",
  "game": "1",
  "nonce": 655,
  "currency": "USD",
  "amount": 0.002,
  "payoutMultiplier": 3.456700086593628,
  "payout": 0.00691339830729166,
  "createdAt": "2020-02-03T05:13:39.204Z",
  "updatedAt": "2020-02-03T05:13:50.819Z",
  "stateGame1": {
    "rounds": [
      {
        "number": 33,
        "answer": "higherEqual",
        "payoutMultiplier": 1.2869999408721924
      },
      {
        "number": 0,
        "answer": "lowerEqual",
        "payoutMultiplier": 1.6730999946594238
      },
      {
        "number": 18,
        "answer": "higherEqual",
        "payoutMultiplier": 1.8125250339508057
      },
      {
        "number": 42,
        "answer": "higherEqual",
        "payoutMultiplier": 2.9453530311584473
      },
      {
        "number": 42,
        "answer": "lowerEqual",
        "payoutMultiplier": 3.1907992362976074
      },
      {
        "number": 20,
        "answer": "lowerEqual",
        "payoutMultiplier": 3.4566991329193115
      }
    ],
    "startCard": 10
  },
  "SeedHash": "b69f0830ef4e0f8996a9de5fd53ea4e4b3fb8897cd2b88122510d4f06c864971",
  "clientSeed": "41ba497f4014"
}

As you can see, under stateGame1 -> rounds, there is "number", "answer", and "payoutMultiplier". My question is how would I go about selecting these data points to render into the datatables child row? Also, the fact that it has "rounds" also kinda throws me off. Im currently able to display data if say the JSON file just has stateGame1, but I'm not sure how to drill down further to rounds. If possible, Id really like to selectively choose the data within rounds, but i'm not sure how to do that given that all of them use the same identifier. To make things even more difficult, the number of data points under rounds can vary. Any ideas on how to accomplish this? Below is my script so far, so you can see how I'm displaying the data on simpler entries with just stateGame1 for example and not using the rounds identifier:

http://live.datatables.net/fefasife/1/edit

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.