EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: forum6691 on April 05, 2014, 10:05:54 AM



Title: How to use loadData for a tree with data contained in a variabble
Post by: forum6691 on April 05, 2014, 10:05:54 AM
I have a tree named "treev"

When I use this code
J('#treev').tree('loadData', [{"id":1,"text":"node1","state":"open"}]);
 all is ok.

When I use a variable $var which contains the string "[{"id":1,"text":"node1","state":"open"}]"
and I Use this code
J('#treev').tree('loadData',$var);
I get an recursive error
too much recursion
http://localhost/Club-Regate/regate/easyui/jquery.min.js Line 4


And a lot of "Undefined" displayed in the tree !

I don't understand this problem. My variable contains the same string than this I put by hand.
Where is the problem ?
Thanks for your help


Title: Re: How to use loadData for a tree with data contained in a variabble
Post by: stworthy on April 05, 2014, 06:44:08 PM
The data to be loaded into tree must be an array not string.
Code:
var data = [{"id":1,"text":"node1","state":"open"}];
$('#tt').tree('loadData', data);


Title: Re: How to use loadData for a tree with data contained in a variabble
Post by: forum6691 on April 05, 2014, 11:10:47 PM
Ok, I understand the needs of an array, but when I put an array, I obtain nothing to the screen

Look at the code:
I have an ajx method from jquery to ask the server
Code:
J.ajax({
  type: 'GET', // Le type de ma requete
  dataType: "json",
  url: '{PATH_TO_ROOT}/regate/?url=/ajax/tree', // L'url vers laquelle la requete sera envoyee
  data: {
    mode: mode // Les donnees que l'on souhaite envoyer au serveur au format JSON
  },
  success: function(data, textStatus, jqXHR) {
    J('#treev').tree('loadData', data);
    //var donnee= jqXHR.responseText;
    //J('#treev').tree('loadData',donnee);
  },   
 error: function(jqXHR, textStatus, errorThrown) {
    // Une erreur s'est produite lors de la requete
alert('Echec de la requete');
  }
 });

My server give me a jsonresponse. With firebug the data contains:
data    Object { id=1, text="node1", state="closed"}

and the jqXHR.responseText contains:
responseText    "{"id":1,"text":"node1","state":"closed"}"

If I use
Code:
 J('#treev').tree('loadData', data); 
I obtain no display in the treeview although data is an array !
If I use
Code:
 var donnee= jqXHR.responseText;
 J('#treev').tree('loadData',donnee);
I obtain "a too much recursion" error and a lot of "undefined" in the treeview


Title: Re: How to use loadData for a tree with data contained in a variabble
Post by: stworthy on April 06, 2014, 07:17:18 AM
My server give me a jsonresponse. With firebug the data contains:
data    Object { id=1, text="node1", state="closed"}

and the jqXHR.responseText contains:
responseText    "{"id":1,"text":"node1","state":"closed"}"

You are returning un-array data. Please check your code carefully. The example below works fine.
http://jsfiddle.net/j2w6g/


Title: Re: How to use loadData for a tree with data contained in a variabble
Post by: forum6691 on April 06, 2014, 08:53:11 AM
I have found a solution. I must add bracket around data
Code:
   J('#treev').tree('loadData', [data]);

With this bracket, it's OK. Strange ?