I have an array of data in $key => $value
pairs that I wanted to display nicely to the user. As I was trying to think of ways to do it, I came up with the though of:
It'd be nice if I could just pass the JSON to the page and have a javascript tree made.
Then I found jsTree, which seemed to fit my requirements perfectly. After reading the documentation, I found the JSON format which was needed to to be passed to create the tree - so I created a recursive function to transform it in to the correct array format, and then json_encode
'd it and passed it to the constructor. The problem was, json_encode
didn't create the children
nodes properly, so it was completely unusable. I like general solutions, without having to format the data from the source for one particular type of display (being jsTree in this case), and decided I'd want to be able to take any array and display it with jsTree efficiently. After hours of searching I was unable to find a drop-in solution to this problem.
So, my question is, what is the best way to convert a PHP array to something that jsTree will play nicely with. Added bonus if the children nodes don't have icons, nor the space where the icon was, as I am personally not dealing with a file system and have no need for an icon where there are no children nodes.