xml data source example for 3.0.0 (upgrading from jstree 1 - xml_data)

545 views
Skip to first unread message

Jessica Smith

unread,
May 30, 2014, 6:16:34 PM5/30/14
to jst...@googlegroups.com
I am trying to upgrade an old site that uses the old jstree xml_data plugin to 3.0.0, but I am having a hard time figuring out how to do that.
On my old site I have:

  $("#widgettree").tree( {
      data  : {
        type  : "xml_flat",
        url   : "http://domain.com/xml_file.xml"
      },
      callback : {
        onselect : function(NODE,TREE_OBJ) {
....

(The callback/onselect part is in there as well because I also couldn't figure out how to do that with 3.0).
Can someone point me in the right direction as to how/whether I can achieve this with 3.0?
Thanks!

Ivan Bozhanov

unread,
May 31, 2014, 2:43:08 AM5/31/14
to jst...@googlegroups.com
Read the docs for v.3 - you have events which are handled the same way you would handle a click event with jQuery.

As for the XML source - that is no longer supported, it would be trivial to write a plugin that reenables this, but I am not going to support it - search this group for XML - someone already wrote such a plugin.

But if I were you I'd switch to JSON, you can even do that if you have no control over the backend - you can use a "proxy" - just use core.data as a function, inside that function grab the XML, convert it to JSON with a few lines of jQuery and call the callback to feed it to jstree.

Best regards,
Ivan

Jessica Smith

unread,
May 31, 2014, 6:52:53 AM5/31/14
to jst...@googlegroups.com
Thanks for the answer and pointing me in the right direction!
I will switch my backend to json. The example on http://www.jstree.com/docs/json/ ("Using AJAX") is confusing to me. Where is the url? How do I set the dataType?
My tree loading icon keep spinning, I tried many ways to pass the url in there.
The documentation here: http://www.jstree.com/api/#/?f=$.jstree.defaults.core.data
says this:
'core' : {
        'data' : {
            'url' : '/get/children/',
            'data' : function (node) {
                return { 'id' : node.id };
            }
        }
    });

That didn't work either. Can you post a full example? I will keep trying and report success or failure - thanks!

Ivan Bozhanov

unread,
May 31, 2014, 7:14:43 AM5/31/14
to jst...@googlegroups.com
core.data is the standard AJAX config. The demo page shows this in action 3 times, sorry, I cannot provide more demos than that.
Reply all
Reply to author
Forward
0 new messages