纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.5 KiB

3 years ago
  1. using System.Collections.Generic;
  2. using System.Text;
  3. namespace NFine.Code
  4. {
  5. public static class TreeGrid
  6. {
  7. public static string TreeGridJson(this List<TreeGridModel> data)
  8. {
  9. StringBuilder sb = new StringBuilder();
  10. sb.Append("{ \"rows\": [");
  11. sb.Append(TreeGridJson(data, -1, "0"));
  12. sb.Append("]}");
  13. return sb.ToString();
  14. }
  15. private static string TreeGridJson(List<TreeGridModel> data, int index, string parentId)
  16. {
  17. StringBuilder sb = new StringBuilder();
  18. var ChildNodeList = data.FindAll(t => t.parentId == parentId);
  19. if (ChildNodeList.Count > 0) { index++; }
  20. foreach (TreeGridModel entity in ChildNodeList)
  21. {
  22. string strJson = entity.entityJson;
  23. strJson = strJson.Insert(1, "\"loaded\":" + (entity.loaded == true ? false : true).ToString().ToLower() + ",");
  24. strJson = strJson.Insert(1, "\"expanded\":" + (entity.expanded).ToString().ToLower() + ",");
  25. strJson = strJson.Insert(1, "\"isLeaf\":" + (entity.isLeaf == true ? false : true).ToString().ToLower() + ",");
  26. strJson = strJson.Insert(1, "\"parent\":\"" + parentId + "\",");
  27. strJson = strJson.Insert(1, "\"level\":" + index + ",");
  28. sb.Append(strJson);
  29. sb.Append(TreeGridJson(data, index, entity.id));
  30. }
  31. return sb.ToString().Replace("}{", "},{");
  32. }
  33. }
  34. }