I am using jstree 3 and having a hard time finding the exact solution to my simple problem.
I wish to display a tree using an ajax load. The idea is that I need to display a tree based on a user selection on the page. So when the selection changes I have to reset the tree and display a different tree. I don't wish to have lazy-loading if I can avoid it, since my tree is usually not that big, so loading the complete tree would be the ideal solution.
As a final note, I already have a tree displayed on that page. The additional tree will be displayed inside a tab in a jquery dialog.
Can anyone give me an example how to accomplish that?
<select id="OutputTarget" onchange="ChangeOutputTarget();">
<option value="1">Dev</option>
<option value="2">QA</option>
<option value="3">Prod</option>
</select>
<div id="OutputFiles" style="height:300px;overflow:scroll">
<ul id="OutputContent">
</ul>
</div>
<script>
function getData(node)
{
var tree = [
{ "id": "1", "parent": "#", "text": "Stuff1", "type": "folder" },
{ "id": "200", "parent": "#", "text": "Stuff2", "type": "default" }, { "id": "300", "parent": "#", "text": "Stuff", "type": "default" },
{ "id": "400", "parent": "#", "text": "Stuff", "type": "default" },
{ "id": "500", "parent": "#", "text": "Stuff", "type": "default" },
{ "id": "600", "parent": "#", "text": "Stuff", "type": "default" },
{ "id": "700", "parent": "#", "text": "Stuff", "type": "default" },
{ "id": "800", "parent": "#", "text": "Stuff", "type": "default" },
{ "id": "900", "parent": "#", "text": "Stuff", "type": "default" },
{ "id": "1000", "parent": "#", "text": "Stuff", "type": "default" },
{ "id": "1100", "parent": "200", "text": "Stuff*", "type": "default" },
{ "id": "1200", "parent": "200", "text": "Stuff*", "type": "default" },
{ "id": "1300", "parent": "500", "text": "Stuff", "type": "default" },
{ "id": "1400", "parent": "500", "text": "Stuff", "type": "default" },
{ "id": "2300", "parent": "1400", "text": "Stuff", "type": "default" },
{ "id": "3500", "parent": "1400", "text": "Stuff", "type": "default" },
{ "id": "3600", "parent": "1400", "text": "Stuff", "type": "default" },
{ "id": "3700", "parent": "1400", "text": "Stuff", "type": "default" }
];
return tree;
}
function ChangeOutputTarget()
{
$('#OutputFiles')
.jstree({
"core" : {
"animation": 0,
"multiple": false,
'data' : {
'data' : function (node) {
return getData(node);
}
}
,
"themes": { "stripes": false }
},
"plugins" : [ "types" ],
"types" : {
"default" : {
"icon" : "/images/file.png"
},
"file" : {
"icon" : "/images/file.png"
},
"folder" : {
"icon" : "/images/folder.png"
}
}
});
}
</script>'data' : function (node, cb) {
cb(getData(node));
}Best regards,...$<span style="background-color:
...function <span style="background-color:transparent;color:rg
I finally got something like this:
<div id=3D"tab-Output" style=3D"text-align:left">
Target: <select id=3D"OutputTarget"
onchange=3D"ChangeOutputTarget();">
</select>
<div id=3D"OutputFiles" class=3D"demo"
style=3D"height:470px;overflow:scroll">
<ul id=3D"OutputContent">
</ul>
</div>
</div>
$(function () {
$('#OutputFiles')
.jstree({
"core" : {
"animation": 0,
"multiple": false,
'data' : function (node, cb) {
return cb(getData(node));
}
,
"themes": { "stripes": false }
},
"plugins" : [ "types" ],
"types" : OutputTypes
});
});
function ChangeOutputTarget()
{
$('#OutputFiles').jstree("refresh");
}
I did not have much time to check if all elements are there.
Let me know if it works for you.
Paul