jsTree jQuery plugin vs Codeigniter (nodes with children not showing up) |
Hey Guys,
I am using jsTree jQuery plugin in a project, I am getting the data correctly to the view, but clicking to the nodes that have children doesn't do anything. Does anybody know what may be wrong? ![]() Code: Controller: Thank you very much!
From the page (https://www.jstree.com/) the HTML should look like this:
Code: <ul> But you are closing your root node immediately. PHP Code: echo '<li>' . $user['department'] . '</li>'; So the js cannot find the sub <ul> with your users in it as it is not enclosed in the parent <li> Hope that makes sense, Paul.
You can use this code.
HTML Code: <ul> <li>Business <ul> <li>Leo Rodriguez</li> </ul> </li> <li>Computer Science <ul> <li>Harry Jones</li> <li>Sabi</li> </ul> </li> </li> <li>IT <ul> <li>Tim Ben</li> </ul> </li> <li>Marketing <ul> <li>John Doe</li> </ul> </li> </ul> PHP Code: <ul> <?php foreach ($users as $key => $value) { ?> <?php if($users[$key]['department'] != $users[$key-1]['department']) { ?> <li><?php echo $users[$key]['department']; ?></li> <ul> <li><?php echo $users[$key]['fullname']; ?></li> </ul> <?php } else { ?> <ul> <li>Sabi</li> </ul> <?php } ?> <?php } ?> </ul> |
Welcome Guest, Not a member yet? Register Sign In |