“JSON a la mesa HTML” Código de respuesta

convertir los datos de JSON en una tabla HTML

var myList = [
  { "name": "abc", "age": 50 },
  { "age": "25", "hobby": "swimming" },
  { "name": "xyz", "hobby": "programming" }
];

// Builds the HTML Table out of myList.
function buildHtmlTable(selector) {
  var columns = addAllColumnHeaders(myList, selector);

  for (var i = 0; i < myList.length; i++) {
    var row$ = $('<tr/>');
    for (var colIndex = 0; colIndex < columns.length; colIndex++) {
      var cellValue = myList[i][columns[colIndex]];
      if (cellValue == null) cellValue = "";
      row$.append($('<td/>').html(cellValue));
    }
    $(selector).append(row$);
  }
}

// Adds a header row to the table and returns the set of columns.
// Need to do union of keys from all records as some records may not contain
// all records.
function addAllColumnHeaders(myList, selector) {
  var columnSet = [];
  var headerTr$ = $('<tr/>');

  for (var i = 0; i < myList.length; i++) {
    var rowHash = myList[i];
    for (var key in rowHash) {
      if ($.inArray(key, columnSet) == -1) {
        columnSet.push(key);
        headerTr$.append($('<th/>').html(key));
      }
    }
  }
  $(selector).append(headerTr$);

  return columnSet;
}
Inexpensive Ibex

JSON a la mesa HTML

Convert JSON to HTML Table
Step 1: Select your input. Option 1 - Choose JSON file Encoding. Option 2 - Enter an URL. ...
Step 2: Choose output options (optional) Output Field Separator: , ; : Bar-| Tab Other-Choose. Include header in first row. ...
Step 3: Generate output. Result Data: Save your result: .htm Download Result EOL:
koder

Respuestas similares a “JSON a la mesa HTML”

Preguntas similares a “JSON a la mesa HTML”

Más respuestas relacionadas con “JSON a la mesa HTML” en HTML

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código