console.log is the most necessary debug tool for javascript ever, but it only works in FireFox with FireBug. Otherwise it gives you an error, could sabotage all of your other javascript. You could just comment them all out before releasing code. OR you can add a condition around it so that it only shows if it won’t error.
For security reasons you may want to comment out the console.logs anyways, but it doesnt hurt to apply this method to make sure it never produces an error.
if(typeof console.log == ‘function’){ console.log(‘your log string or object here’); }
Tags: JavaScript
I thought I’d be spending a few hours creating a nice reusable way to turn a flat query result into a hierarchial array so I could use it on things like trees or HTML or whatever. When I wrote it out on paper though I felt stupid because the solution was extremely simple.
Assume you have a query result or data like this:
container1 parentA child11
container1 parentA child12
container1 parentB child13
container2 parentC child14
container2 parentC child15
and so on.
every column represents a parent of the column to its right. Duplicates in the columsn let you know which things get grouped together. The solution to turn this into a hierarchy is:
$arrTree[container][parent][child]
you can follow the same pattern indefinately, change the values and the keys as needed. The simplicity in the solution is that by using the columns as the keys it automatically creates them as unique and puts the children under them correctly. I hope this save someone else the paper epiphany
I’m having good success with the jQuery Checktree plugin which can be found here: http://static.geewax.org/checktree/
I added a config option that allows the tree to start collapsed or expanded. It defaults to the current behavior (Collapsed).
In order to start with the checktree expanded define it like this:
jQuery("div#formMedia .checkTree").checkTree({
collapsedarrow: "../collapsed.gif",
expandedarrow: "../expanded.gif",
blankarrow: "../check0.gif" ,
collapseOnInit: false
})
The updated code can be found *here*