EasyUI Forum
March 29, 2024, 04:28:01 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: About JSON  (Read 18327 times)
nyr_jack
Newbie
*
Posts: 31


View Profile
« on: January 30, 2013, 12:38:38 AM »

Who has java source codes about converting ArrayList to JSON format of easyui-tree ??
Logged
mzeddd
Full Member
***
Posts: 223



View Profile
« Reply #1 on: January 30, 2013, 02:53:11 AM »

I have question to EasyUI developers from the same area: Can we get possibility to use the same JSON data format for Tree as we use for TreeGrid?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #2 on: January 30, 2013, 03:00:36 AM »

Using 'loadFilter' function and you will be able to change any data to the standard data format for tree.
Logged
nyr_jack
Newbie
*
Posts: 31


View Profile
« Reply #3 on: February 01, 2013, 12:10:28 AM »

Can you show me a sample? please!
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #4 on: February 01, 2013, 01:08:40 AM »

Here is the example shows how to use 'loadFilter' function.
Code:
<ul class="easyui-tree" data-options="data:treedata,loadFilter:treeFilter"></ul>
Code:
var treedata = [
{"id":1,"name":"All Tasks","begin":"3/4/2010","end":"3/20/2010","progress":60,"iconCls":"icon-ok"},
{"id":2,"name":"Designing","begin":"3/4/2010","end":"3/10/2010","progress":100,"_parentId":1,"state":"closed"},
{"id":21,"name":"Database","persons":2,"begin":"3/4/2010","end":"3/6/2010","progress":100,"_parentId":2},
{"id":22,"name":"UML","persons":1,"begin":"3/7/2010","end":"3/8/2010","progress":100,"_parentId":2},
{"id":23,"name":"Export Document","persons":1,"begin":"3/9/2010","end":"3/10/2010","progress":100,"_parentId":2},
{"id":3,"name":"Coding","persons":2,"begin":"3/11/2010","end":"3/18/2010","progress":80},
{"id":4,"name":"Testing","persons":1,"begin":"3/19/2010","end":"3/20/2010","progress":20}
];
function treeFilter(rows){
for(var i=0; i<rows.length; i++){
rows[i]['text'] = rows[i]['name'];
}
var nodes = [];
// get the top level nodes
for(var i=0; i<rows.length; i++){
var row = rows[i];
if (!row._parentId){
nodes.push(row);
rows.splice(i,1);
i--;
}
}
var toDo = [];
for(var i=0; i<nodes.length; i++){
toDo.push(nodes[i]);
}
while(toDo.length){
var node = toDo.shift(); // the parent node
// get the children nodes
for(var i=0; i<rows.length; i++){
var row = rows[i];
if (row._parentId == node.id){
if (node.children){
node.children.push(row);
} else {
node.children = [row];
}
toDo.push(row);
rows.splice(i,1);
i--;
}
}
}
return nodes;
}
Logged
nyr_jack
Newbie
*
Posts: 31


View Profile
« Reply #5 on: February 05, 2013, 01:42:46 AM »

Thanks! It's very useful !
Logged
dailyblog
Newbie
*
Posts: 30


View Profile Email
« Reply #6 on: October 29, 2016, 04:58:41 PM »

With 5 loop statements, the code performance will be reduced?
Logged
catpaw
Jr. Member
**
Posts: 85


View Profile Email
« Reply #7 on: February 13, 2017, 12:01:03 PM »

+1

 Grin
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!