Convert JSON array to an HTML table in jQuery

前端 未结 15 1081
温柔的废话
温柔的废话 2020-11-22 16:33

Is there a really easy way I can take an array of JSON objects and turn it into an HTML table, excluding a few fields? Or am I going to have to do this manually?

15条回答
  •  [愿得一人]
    2020-11-22 16:52

    Pivoted single-row view with headers on the left based on @Dr.sai's answer above.

    Injection prevented by jQuery's .text method

    $.makeTable = function (mydata) {
        var table = $('');
        $.each(mydata, function (index, value) {
            // console.log('index '+index+' value '+value);
            $(table).append($(''));
            $(table).append($('
    ').text(index)); $(table).append($('').text(value)); }); return ($(table)); };

    提交回复
    热议问题