EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: sky-t on March 24, 2020, 06:24:21 AM



Title: Tree data to string
Post by: sky-t on March 24, 2020, 06:24:21 AM
Hi there,

is there a chance to convert whole tree data incl. children to a string (JSON) to send it to a server?



Thank yout


Title: Re: Tree data to string
Post by: jarry on March 26, 2020, 08:31:36 PM
Please use JSON.stringify to convert the JSON object to a string.
Code:
var s = JSON.stringify(...);
console.log(s);


Title: Re: Tree data to string
Post by: sky-t on March 28, 2020, 01:21:31 AM
Hi jarry,

thank you for your reply.

I use this code:
Code:
        var data=$('#tree_main_west').tree('getData', roots[i].target);
        var s = JSON.stringify(data);

And get the error:

Uncaught TypeError: Converting circular structure to JSON


How can i solve this problem?


Title: Re: Tree data to string
Post by: jarry on March 29, 2020, 01:57:25 AM
This code get all the tree data and stringnify it.
Code:
var data = $('#tt').tree('getData',$('#tt').tree('getRoot').target)
var s = JSON.stringify(data);
console.log(s)