How to access a JSON value and insert into data-id?

1

I have this JSON:

{draw: 1, recordsTotal: 16, recordsFiltered: 16, data: [,…]}

and within data , for example a record:

0: ["1", "FooBar", "00.000.000/0000-00", "13600-000", "Rua Santos Dumont", "Curitiba", "Jardim X", "ID_1"]

How can I get just the number of ID_1 and put it in data-id :

<a data-toggle="modal" data-target="#infoModal" data-id:"**COLOCAR AQUI**" id="getPublication" class="blue"><i class="ace-icon fa fa-search-plus bigger-130"></i></a>
    
asked by anonymous 07.07.2017 / 22:54

1 answer

2

You just need to iterate obj.data and generate <a> with the array index.

Example:

var obj = {
  draw: 1,
  recordsTotal: 16,
  recordsFiltered: 16,
  data: [
    ["1", "FooBar", "00.000.000/0000-00", "13600-000", "Rua Santos Dumont", "Curitiba", "Jardim X", "ID_1"]
  ]
}

obj.data.forEach(function(data) {
  var a = '<a data-toggle="modal" data-target="#infoModal" data-id= "' + data[7] + '" id="getPublication" class="blue"><i class="ace-icon fa fa-search-plus bigger-130">' + data[4] + '</i></a>';
  document.body.innerHTML += a;
});
    
07.07.2017 / 23:00