EasyUI Forum
March 28, 2024, 12:36:53 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How to use loadData for a tree with data contained in a variabble  (Read 12589 times)
forum6691
Newbie
*
Posts: 39


View Profile
« 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
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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);
Logged
forum6691
Newbie
*
Posts: 39


View Profile
« Reply #2 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
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 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/
Logged
forum6691
Newbie
*
Posts: 39


View Profile
« Reply #4 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 ?
« Last Edit: April 06, 2014, 11:05:16 AM by forum6691 » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!