“json ke tabel html” Kode Jawaban

Konversi data JSON ke tabel 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 ke tabel 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

Jawaban yang mirip dengan “json ke tabel html”

Pertanyaan yang mirip dengan “json ke tabel html”

Lebih banyak jawaban terkait untuk “json ke tabel html” di HTML

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya