Created
June 6, 2017 12:02
-
-
Save beppe9000/39c42466794d739d22529cf3a520b077 to your computer and use it in GitHub Desktop.
2-column mode table from JSON associative array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function writeTable(tbody, ark, title) { | |
var td_style = 'padding:5px 10px;border:1px solid black'; | |
var tble_style = 'border:1px solid black'; | |
tbody.empty(); | |
$('<tr/>').appendTo(tbody).append('<th colspan="4"><b>'+title+'</b></td>'); | |
var tr = $('<tr/>').appendTo(tbody); | |
ark.forEach(function(itm,idx){ | |
console.log("ITM"+idx+": NN="+itm.nn+" BB="+itm.bb); | |
if (idx % 2 === 0) tr = $('<tr/>').appendTo(tbody); | |
tr.append('<td style="'+td_style+'">' + itm.nn + '</td>'); | |
tr.append('<td style="'+td_style+'">' + itm.bb + '</td>'); | |
});} | |
var ark = JSON.parse('[{"nn":"BLU","bb":0},{"nn":"VERDI","bb":-6},{"nn":"NERO","bb":0},{"nn":"VIOLA CALDI","bb":-54},{"nn":"GIALLI","bb":0},{"nn":"GIALLI CALDI","bb":0},{"nn":"GIALLI PRECOCI","bb":-124},{"nn":"GIALLI PRECOCI CALDI","bb":-147},{"nn":"VERDI PRECOCI","bb":-97},{"nn":"ROSSI","bb":0},{"nn":"MINI VERDI","bb":2},{"nn":"DOPPI","bb":-9}]'); | |
writeTable( $('#my-table'), ark, "THIS IS A 4-COLUMN HEADER TITLE") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment