MySQL tree query results are encapsulated in JSON format and returned to Easyui Treegrid

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.