HTML Table to JSON

前端 未结 7 1929
小鲜肉
小鲜肉 2020-11-29 06:56

I need to take table rows and convert to JSON.

Any ideas? I have this code here but it does not work.

function tableToJSON(tableID) {
    return $(t         


        
7条回答
  •  半阙折子戏
    2020-11-29 07:20

    HTML table with thead and tbody:

        function htmlTableToJson(table, edit = 0, del = 0) {
            // If exists the cols: "edit" and "del" to remove from JSON just pass values = 1 to edit and del params
            var minus = edit + del;
            var data = [];
            var colsLength = $(table.find('thead tr')[0]).find('th').length - minus;
            var rowsLength = $(table.find('tbody tr')).length;
    
            // first row needs to be headers
            var headers = [];
            for (var i=0; i

提交回复
热议问题