I think your best option here is to use AJAX and dynamic load of data.
On your javascript code bind the click event of your first level nodes to an AJAX call to a method on the server.
This method should: check if the node has children, if it has then return the list of children associated to it, if it hasn't it should return some info adverting your client code about it.
Your AJAX call on success should check if receive a list of subnodes or a message adverting that there's no subnodes. If it has the subnodes just append them to your html structure, if it hasn't do nothing (or whatever you want to do when clicking on a top node without children).
From here you can make your system grow in complexity as much as you want, using different methods for different node levels and behaviours, etc...