Convert JSON array to an HTML table in jQuery

前端 未结 15 898
温柔的废话
温柔的废话 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:44

    A still shorter way

    $.makeTable = function (mydata) {
                if (mydata.length <= 0) return "";
               return $('').append("" + $.map(mydata[0], function (val, key) {
                    return "";
                }).join("\n") + "").append($.map(mydata, function (index, value) {
                    return "" + $.map(index, function (val, key) {
                        return "";
                    }).join("\n") + "";
                }).join("\n"));
            };
    

    提交回复
    热议问题
    " + key + "
    " + val + "