Child rows (show extra / detailed information) Nesting json data

Child rows (show extra / detailed information) Nesting json data

Gonzalo2683Gonzalo2683 Posts: 1Questions: 0Answers: 0
edited November 2014 in Free community support

Greetings, I have a question
As I can access data in a file nested. I'm using the code as shown in the example.

With data from first level I have no problem, but if I have problems with the second level

I have a file with a structure like this:
(For some reason when i paste the json file, the mail key return a script tag only here in the markdown syntax) this is not present in the original json file.

{
  "data": [
    {
      "nombre": "Juan",
      "apellido": "Montero",
      "direccion": "Juan M. Blanes",
      "barrio": "Malvin",
      "edad": 23,
      "publicado": "2014-12-23T00:00:00.000Z",
      "poblacion": 100000,
      "ocupacion": "Maestro",
      "ingresos": 20000,
      "natalidad": "Diaria",
      "salidas": 18000,
      "prestamos": 23000,
      "empresa": "Google",
      "mail": "testing@test.com",
      "privado": [
        {
          "nacionalidad": "Turca",
          "estadoCivil": "casado",
          "hijos": [
            {
              "nombre": "Mario",
              "apellido": "Parrosa"
            }
          ],
          "esposa": "Marisol",
          "madre": "Paola",
          "padre": "Marco"
        }
      ]
    },
    {
      "nombre": "Mateo",
      "apellido": "Marquez",
      "direccion": "Luis A Ridriguez",
      "barrio": "Peñarol",
      "edad": 45,
      "publicado": "2014-12-18T00:00:00.000Z",
      "poblacion": 500000,
      "ocupacion": "Policia",
      "ingresos": 10000,
      "natalidad": "Mensual",
      "salidas": 12000,
      "prestamos": 28000,
      "empresa": "Bing",
      "mail": "dummy@test.com",
      "privado": [
        {
          "nacionalidad": "Kurdo",
          "estadoCivil": "Viudo",
          "hijos": [
            {
              "nombre": "Kiko",
              "apellido": "Palares"
            }
          ],
          "esposa": "Marcela",
          "madre": "Gioconda",
          "padre": "Alejandro"
        }
      ]
    }
  ]
}

Try this and does not work
If you use the same format function only returns it as undefined.

function format ( d ) {
        // `d` is the original data object for the row
        return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+
            '<tr>'+
                '<td>Mail:</td>'+
                '<td>'+d.mail+'</td>'+
            '</tr>'+
            '<tr>'+
                '<td>Empresa:</td>'+
                '<td>'+d.empresa+'</td>'+
            '</tr>'+
            '<tr>'+
                '<td>Privado:</td>'+
                '<td>'+d.privado.nacionalidad+'</td>'+
            '</tr>'+
            '<tr>'+
                '<td>Información Adicional:</td>'+
                '<td>And any further details here (images etc)...</td>'+
            '</tr>'+
        '</table>';
    }

What is the correct way to do?

Replies

  • allanallan Posts: 61,950Questions: 1Answers: 10,158 Site admin

    For some reason when i paste the json file, the mail key return a script tag only here in the markdown syntax

    That was CloudFlare trying to protect e-mail addresses. It was doing more harm than good and I've just disabled it!

    d.privado.nacionalidad

    Doesn't work because privado doesn't have a property called nacionalidad. privado is an array! So you would need to use something like:

    d.privado[0].nacionalidad
    

    Allan

This discussion has been closed.