I have tree data in mysql table. I have ID and parentID. I wish to display a tree structure with Ajax. When I click on the node, I want to sent a parameter to a page and return a data and then use the data to display the children.
<body>
<div id='jstree'>
</div>
<script>
$(function () {
// 6 create an instance when the DOM is ready
$('#jstree').jstree({
'core' : {
'data' : {
'url' : 'abc.asp?',
'data' : function (node) {
return { 'accno' : node.id };
}
}
}
});
// 7 bind to events triggered on the tree
$('#jstree').on("changed.jstree", function (e, data) {
console.log(data.selected);
});
// 8 interact with the tree - either way is OK
$('button').on('click', function () {
$('#jstree').jstree(true).select_node('child_node_1');
$('#jstree').jstree('select_node', 'child_node_1');
$.jstree.reference('#jstree').select_node('child_node_1');
});
});
</script>
</body>
I really hope you guys can help me out. What I want to achieve after my research is called lazy loading. Say I have a sql table with the following data.
Accno Referral L1A L1B L2A1 L1A L2A2 L1A L2A3 L1A L2B1 L1B L2B2 L1B L2B3 L1B L3A1 L2A1 L3A2 L2A1 L3B1 L2B3 L3B2 L2B2 and so on
- Initially I want to load L1A and L1B with + sign indicates they have children
- When clicked on the node with children, say L1A.
- How to pass a url with parameter of accno L1A to another page to process? How to indicate node.id is L1A(will it automatically be detected when I click on the node?)
- Pass the url abc.asp?accno="L1A" to a html/asp page to process.
- Find the children with accno="L1A" in SQL statement, select .... with referral = 'L1A' flag the results for those with children and those without children.
- Return the results.
- How do I return results, in HTML file? I can format it in any strings but what is format?
- And, how does JSTREE pick up the results and display?
Please help.