Private string createtreejson (list<schedjob> list) { jsonarray rootarray = new jsonarray (); for ( Int i=0; i<list.size (); i++) { SchedJob Resource = list.get (i); system.out.println ( Resource.getjobid () + "--------" +resource.getparentjobid ()); //parent_ job_id=0 represents the root node if (resource.getparentjobid () == 0) { jsonobject rootobj = createbranch (List, resource); Rootarray.add (rootobj); } } &nbsP; return rootarray.tostring (); } /** * Recursive creation of branch node JSON objects * @param list Create tree raw data * @param currentNode current node * @return Current node and child nodes of this node JSON object */ private jsonobject createbranch (list<schedjob> list, schedjob currentnode) { /* * Parse the JavaBean object into a JSON object */ Jsonobject currentobj = jsonobject.fromobject (CurrentNode); Jsonarray childarray = new jsonarray (); /* *&nbThe SP loops through the original data list, judging if the parent ID value of an object in the list is equal to the ID value of the current node, * if equal, go to recursively create a child node of the new node, Until there are no child nodes, the node is returned and the * node is placed in the list of child nodes of the current node */ for (Int i=0; i<list.size (); i++) { schedjob newnode = list.get (i); if (Newnode.getparentjobid ()!=null && Newnode.getparentjobid (). CompareTo (Currentnode.getjobid ()) == 0) { jsonobject childobj = createbranch (List, newNode); childarray.add (childobj); } } /* * determines whether the current child node array is empty, does not empty the child node array into the Children field */ if (!childarray.isempty ()) { currentobj.put ("Children", childarray); } return currentObj; }
MySQL tree query results are encapsulated in JSON format and returned to Easyui Treegrid
MySQL tree query results are encapsulated in JSON format and returned to Easyui Treegrid