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