开发者

jsTree get_json function

I have a jstree tree that I'm trying to extract the structure of using get_json (in order to post it back to the server), but I don't seem to be getting any tree info in the returned object.

The tree is setup and working properly in

$("#site-structure-container").jstree({plugins : ["themes", "json_data"]});

(excluded above is the json I've supplied (from the first demo here) to setup the tree) and I'm using

data = $("#site-structure-container").jstree("get_json", -1);
console.log(JSON.stringify(data));

to check whats extracted. This is what is shown in the log:

{"length":1,"0":{"jQuery16203561271743551655":3},"context":{"jQuery16203561271743551655":1},"selector":"#site-structure-container"}

Surely I should be getting the tree structure in here? What am I doing wrong?

UPDATE:

Have eventually tracked it down to jQuery version.. 1.6.2 (which I was using) doesn't appear to work in the same way that 1.4 to 1开发者_如何学运维.6.1 do. Changing to any 1.4 to 1.6.1 means I get the result I expected ie.:

[{"data":{"attr":{},"title":"A node","icon":"checkbox"},"attr":{"id"...

I don't know exactly what is going wrong with 1.6.2+, but I've found it doesn't make any difference whether I use .jstree("get_json") or .jstree("blahblah") or .jstree(), I always get the same unexpected output as above ({"length":1...).


Refer the following url,

http://javahunter.wordpress.com/2011/02/26/jquery-tree-using-json-as-dataset/

UPDATE:

Use the following code you can declare an alternate variable for $,

          var $j = jQuery.noConflict();

Then use $j for jQuery, instead of $.

If this is the conflict issue the above will solve it. Normally conflicts occur if an external library is used other than Jquery library.

note: be sure to include jQuery1.6.2.js after the other library, so it knows what to give $ back to.

Hope this helps you...


Have eventually tracked it down to jQuery version.. 1.6.2 (which I was using) doesn't appear to work in the same way that 1.4 to 1.6.1 do. Changing to any 1.4 to 1.6.1 means I get the result I expected ie.:

[{"data":{"attr":{},"title":"A node","icon":"checkbox"},"attr":{"id"...

I don't know exactly what is going wrong with 1.6.2, but I've found it doesn't make any difference whether I use .jstree("get_json") or .jstree("blahblah") or .jstree(), I always get the same unexpected output as above ({"length":1...).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜