Easyui tree background data initialization (LINQ Operation)

Source: Internet
Author: User

Controller:

1 /// <summary> 2 // tree initialization 3 /// </Summary> 4 /// <returns> </returns> 5 [httppost] 6 Public contentresult inittree () 7 {8 list <testmodel> items = BLL. gettreeformlist (); 9 action <testmodel> setchildren = NULL; 10 // encapsulate a method (recursion) to constantly read the branches of the tree 11 setchildren = parent => 12 {13 parent. children = items. where (childitem => childitem. parentguid = parent. guid ). tolist (); 14 parent. children. foreach (setchildren); 15}; 16 // initialization tree list 17 list <testmodel> treeitems = items. where (rootitem => rootitem. parentguid = ""). tolist (); 18 treeitems. foreach (setchildren); 19 20 string strjson = jsonconvert. serializeobject (treeitems, 21 formatting. indented, 22 new jsonserializersettings () 23 {24 nullvaluehandling = nullvaluehandling. ignore, 25 referenceloophandling = referenceloophandling. ignore, 26 converters = new list <jsonconverter> {New isodatetimeconverter {datetimeformat = "yyyy-mm-dd hh: mm: SS" }}27 }). replace ("children", "children"); 28 29 return content (strjson); 30}
View code

Entity:

1     public class TestModel2     {3         public string Guid { get; set; }4         public string Name { get; set; }5         public string Price { get; set; }6         public string ParentGuid { get; set; }7 8         public List<TestModel> Children { get; set; }9     }
View code

 

Easyui tree background data initialization (LINQ Operation)

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.