EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: nyr_jack on January 30, 2013, 12:38:38 AM



Title: About JSON
Post by: nyr_jack on January 30, 2013, 12:38:38 AM
Who has java source codes about converting ArrayList to JSON format of easyui-tree ??


Title: Re: About JSON
Post by: mzeddd 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?


Title: Re: About JSON
Post by: stworthy 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.


Title: Re: About JSON
Post by: nyr_jack on February 01, 2013, 12:10:28 AM
Can you show me a sample? please!


Title: Re: About JSON
Post by: stworthy 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;
}


Title: Re: About JSON
Post by: nyr_jack on February 05, 2013, 01:42:46 AM
Thanks! It's very useful !


Title: Re: About JSON
Post by: dailyblog on October 29, 2016, 04:58:41 PM
With 5 loop statements, the code performance will be reduced?


Title: Re: About JSON
Post by: catpaw on February 13, 2017, 12:01:03 PM
+1

 ;D