EasyUI Forum
May 03, 2024, 01:58:08 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Tree and JSON Data  (Read 19882 times)
LdyMox
Newbie
*
Posts: 5


View Profile
« on: June 04, 2012, 06:49:30 AM »

I can not seem to figure our how to get back the JSON data for the current places of the Tree UI. I am trying to use the JSON data and hope to pass the values via a form so I can save the data for later use.
Logged
LdyMox
Newbie
*
Posts: 5


View Profile
« Reply #1 on: June 05, 2012, 08:01:07 AM »

I need to get the data back somehow, anyways so I can save the data. Loading is no problem, but can't figure how to access the current state of the tree so I can use it.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #2 on: June 05, 2012, 06:22:41 PM »

Call 'getData' method to get a node data, get the root node data and store it in somewhere. To restore the tree, call 'loadData' method and pass the original root node data as its parameter. The code looks like this:
Code:
var root = $('#tt').tree('getRoot');  // get root node
var data = $('#tt').tree('getData', root.target);  // get the root node data
// now restore the tree
$('#tt').tree('loadData', [data]);

The 'getData' method is implemented as below:
Code:
$.fn.tree.methods.getData = function(jq, target){
function retrieveChildData(aa, ul){
ul.children('li').each(function(){
var node = $(this).children('div.tree-node');
var nodedata = jq.tree('getNode', node[0]);
var sub = $(this).children('ul');
if (sub.length){
nodedata.children = [];
retrieveChildData(nodedata.children, sub);
}
aa.push(nodedata);
});
}
var nodedata = jq.tree('getNode', target);
nodedata.children = [];
retrieveChildData(nodedata.children, $(target).next());
return nodedata;
};
Logged
LdyMox
Newbie
*
Posts: 5


View Profile
« Reply #3 on: June 06, 2012, 05:51:51 AM »

Ahh thank you! I knew there had to be something I was missing!
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!