plork wrote:
I'm trying to code a tree structure using javascript, the nodes of the
tree are generated from a sql table. Has anyone some code for this?
Cheers
I'm not sure what you mean by "tree structure". Presumably you want a
table-oriented object to store data retrieved from the results of an SQL
query?
<script type="text/javascript">
var rows = [
<%
for (var i = 0; i < numberOfRows; i++) {
Response.write(i > 0 ? ",\n[" : "[");
for (var j = 0; j < numberOfColumns; j++) {
Response.write(
(j > 0 ? ", " : "") +
"'" +
queryResults.rows[i].columns[j] +
"'"
);
}
Response.write(" ]");
}
%>
];
</script>
Some possible issues with the above code (well, aside from the fact that
it is ASP psuedogibberish intended to give you the idea of how to populate
a client-side Array of Arrays from server-side code):
1) If the query results contain a single quote or new line character, it
would generate client-side JavaScript that contains a syntax error. This
could be fixed by inserting '\n' for newline characters and escaping
single quotes.
2) You lose your column names, to retain them, you could store an Object
or Array of objects in each row[] Array entry, but the code gets a bit
more complex.
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ -
http://jibbering.com/faq