. NET Easyui Tree-like structure

Source: Internet
Author: User

Simple background Authoring Write a JSON (string type) format

 Public Partial classgoodstype_type:system.web.ui.page{ Public stringDataList ="", tree=""; Goodstypemanage BLL=NewGoodstypemanage (); Goodstype Model=NewGoodstype (); protected voidPage_Load (Objectsender, EventArgs e) {        if(!IsPostBack) {DataList=getlist (); //tree = Gettree ("0");        }    }    protected stringgetlist () {strings =""; DataTable Data=BLL.        Getalllist (); foreach(DataRow rowinchdata. Rows) {s+="{\ "id\":"+ row["ID"]. ToString () +", \ "parentid\":"+ row["ParentID"]. ToString () +", \ "name\": \ ""+ row["name"]. ToString () +"\"},"; }        if(s! ="") {s= S.substring (0, S.length-1); }        returns; }

Data processing at the foreground Easyui the style used by the tree structure

 <Scripttype= "Text/javascript">       functionconvert (rows) {functionexists (rows, parentid) { for (varI= 0; I<rows.length; I++) {                   if(Rows[i].id==ParentID)return true; }               return false; }           varnodes= []; //get the top level nodes            for (varI= 0; I<rows.length; I++) {               varRow=Rows[i]; if (!exists (rows, Row.parentid))                   {Nodes.push ({id:row.id, text:row.name               }); }           }           varToDo= [];  for (varI= 0; I<nodes.length; I++) {Todo.push (nodes[i]); }            while(todo.length) {varnode=Todo.shift ();//The parent node               //Get the Children nodes                for (varI= 0; I<rows.length; I++) {                   varRow=Rows[i]; if(Row.parentid==node.id) {var Child={id:row.id, text:row.name}; if(Node.children) {Node.children.push (child); } Else{Node.children=[child];                   } todo.push (child); }               }           }           returnnodes; }            $(function () {           $('#tt'). Tree ({data: [<%=DataList%>], Loadfilter:function(rows) {returnconvert (rows);           }           });           Gettypetree (); //$ (' #tree '). Combotree ({           //onselect:function (node)           // {           // }        //  });       }); </Script>    <Divstyle= "float:left; width:40%">        <ulID= "tt">        </ul>    </Div>

The second is the recursive JSON format used by the tree to directly use

Link URL: https://www.cnblogs.com/yonex/p/3379362.html

The Java page is also a recursive link: https://www.cnblogs.com/20gg-com/p/6206502.html

. NET Easyui Tree-like structure

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.