Update jsTree with json data

7,295 views
Skip to first unread message

Anurag

unread,
Dec 14, 2010, 8:18:15 AM12/14/10
to jsTree
To create a jsTree using json data is easy e.g.

theTree.jstree({
plugins: ["themes", "json_data", "crrm", "ui", "unique",
"types"],
json_data : {
data: myJsonData
}
})

But i couldn't find a way to update tree, with new data e.g. I want to
sync my two trees or have got data from an existing ajax call and want
to update tree with that data,

so is there something like this

theTree.jstree('set_json', myJsonData)

atleast naive call like this doesn't work :(

theTree.jstree({
json_data : {
data: myNewJsonData
}
})

I hoped it will update the existing tree

vakata

unread,
Dec 18, 2010, 2:41:39 AM12/18/10
to jsTree
You can have jstree read directly from the server, and then it will be
a matter of calling tree-instance.jstree("refresh");
If that is not applicable you will have to do:
$.jstree.focused()._get_settings().json_data.data = newData;
$.jstree.focused().refresh(-1);

That should do it.

Kindest regards,
Ivan

Yacov Schondorf

unread,
Oct 6, 2014, 7:46:32 AM10/6/14
to jst...@googlegroups.com
Hi,

I know this is an old question, but I have the same problem and $.jstree.focused() returns "TypeError: undefined is not a function". I am not sure even what version of jstree I am using (how can I tell?).
Thanks

Yacov

Yacov Schondorf

unread,
Oct 6, 2014, 8:35:24 AM10/6/14
to jst...@googlegroups.com
Some more info: I found that I have $.jstree._focused().get_settings().json_data.data but its value is false.
I tried 
var children =$('#my-tree').jstree('get_json', -1);
...modify children...
$.jstree._focused().get_settings().json_data.data = JSON.stringify(children) but this did not work.

Ivan Bozhanov

unread,
Oct 6, 2014, 9:58:47 AM10/6/14
to jst...@googlegroups.com
I answered your other question with v.3 code (sorry, I thought you were using v.3). I hope someone here will be able to help you, I just wanted to let you know v.1 is no longer supported, so I will not be able to help you with the problem.

Best regards,
Ivan
Reply all
Reply to author
Forward
0 new messages