converting javascript array into html table in new window on click -
i creating data visualizations, , have button execute javascript function , extract first 5 rows specified columns of data based on user's selection:
getselection.onclick = function() { visual.document.selection.getselection( "city", \\identifies selection "users", \\identifies table ["name", "phone", "zipcode"], \\identifies columns 5, function(args) { log(dump(args, "visual.document.selection.getselection", 2)); }); };
the resulting output looks this:
[name] 0: xxxxx 1: xxxxx 2: xxxxx [phone] 0: xxxxx 1: xxxxx
what display results of users selection in html table in new window opens upon click. have seen suggestions doing similar this, reason can't seem them work. here have far:
function getselmarking() { visual.document.selection.getmarking( "city", "users", ["name", "phone", "zipcode"], 5, function(args) { var userids=dump(args); htmlstring='<html>\n'; htmlstring+='<head>\n'; htmlstring+='<title>new document</title>\n'; htmlstring+='</head>\n'; htmlstring+='<body>\n'; htmlstring+='<p>hello world</p>\n'; htmlstring+='<table>\n'; htmlstring+='<tr>\n'; htmlstring+='<td>'+userids+'</td>\n'; htmlstring+='<td>'+userids+'</td>\n'; htmlstring+='<td>'+userids+'</td>\n'; htmlstring+='</tr>\n'; htmlstring+='</table>\n'; htmlstring+='</body>\n'; htmlstring+='</html>'; newwindow=window.open(); newdocument=newwindow.document; newdocument.write(htmlstring); newdocument.close(); } ); }
thats far i've gotten. stuck on - maybe don't have understanding of how functions work? regardless, thank can lend type of assistance here.
i forgot include breakdown of dump() function:
var dump = function(obj, name, indent, depth) { if (depth > max_dump_depth) { return indent + name + ": <maximum depth reached>\n"; } if (typeof(obj) == "object") { var child = null; var output = name + "\n"; indent += "\t"; (var item in obj) { try { if (item.charat(0) == '_') { continue; } child = obj[item]; } catch (e) { child = "<unable evaluate>"; } if (typeof child == "object") { output += dump(child, item, indent, depth + 1); } else if (typeof(child) == "function") { var functionname = string(child); functionname = functionname.substring(0, functionname.indexof("{", 0) - 10} output += "\t" + item + ": " + functionname + "\n"; } else { var value = ""; if (child == null) { value = "[null]"; } else { value = child; } output += "\t" + item + ": " + value + "\n"; } } return output + "\n"; } else { return obj; } };
i found answer own question. difficulty here caused lack of understanding how javascript handled arrays. sorry everyone.
Comments
Post a Comment