添加项目文件。
This commit is contained in:
60
HT.Cloud.Code/Web/TreeView/TreeView.cs
Normal file
60
HT.Cloud.Code/Web/TreeView/TreeView.cs
Normal file
@ -0,0 +1,60 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2016 HT.Cloud.Framework 版权所有
|
||||
* Author: HT.Cloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace HT.Cloud.Code
|
||||
{
|
||||
public static class TreeView
|
||||
{
|
||||
public static string TreeViewJson(this List<TreeViewModel> data, string parentId = "0")
|
||||
{
|
||||
StringBuilder strJson = new StringBuilder();
|
||||
List<TreeViewModel> item = data.FindAll(t => t.parentId == parentId);
|
||||
strJson.Append("[");
|
||||
if (item.Count > 0)
|
||||
{
|
||||
foreach (TreeViewModel entity in item)
|
||||
{
|
||||
strJson.Append("{");
|
||||
strJson.Append("\"id\":\"" + entity.id + "\",");
|
||||
strJson.Append("\"text\":\"" + entity.text.Replace(" ", "") + "\",");
|
||||
strJson.Append("\"value\":\"" + entity.value + "\",");
|
||||
if (entity.title != null && !string.IsNullOrEmpty(entity.title.Replace(" ", "")))
|
||||
{
|
||||
strJson.Append("\"title\":\"" + entity.title.Replace(" ", "") + "\",");
|
||||
}
|
||||
if (entity.img != null && !string.IsNullOrEmpty(entity.img.Replace(" ", "")))
|
||||
{
|
||||
strJson.Append("\"img\":\"" + entity.img.Replace(" ", "") + "\",");
|
||||
}
|
||||
if (entity.checkstate != null)
|
||||
{
|
||||
strJson.Append("\"checkstate\":" + entity.checkstate + ",");
|
||||
}
|
||||
if (entity.parentId != null)
|
||||
{
|
||||
strJson.Append("\"parentnodes\":\"" + entity.parentId + "\",");
|
||||
}
|
||||
strJson.Append("\"showcheck\":" + entity.showcheck.ToString().ToLower() + ",");
|
||||
strJson.Append("\"isexpand\":" + entity.isexpand.ToString().ToLower() + ",");
|
||||
if (entity.complete == true)
|
||||
{
|
||||
strJson.Append("\"complete\":" + entity.complete.ToString().ToLower() + ",");
|
||||
}
|
||||
strJson.Append("\"hasChildren\":" + entity.hasChildren.ToString().ToLower() + ",");
|
||||
strJson.Append("\"ChildNodes\":" + TreeViewJson(data, entity.id) + "");
|
||||
strJson.Append("},");
|
||||
}
|
||||
strJson = strJson.Remove(strJson.Length - 1, 1);
|
||||
}
|
||||
strJson.Append("]");
|
||||
return strJson.ToString();
|
||||
}
|
||||
}
|
||||
}
|
24
HT.Cloud.Code/Web/TreeView/TreeViewModel.cs
Normal file
24
HT.Cloud.Code/Web/TreeView/TreeViewModel.cs
Normal file
@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2016 HT.Cloud.Framework 版权所有
|
||||
* Author: HT.Cloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
namespace HT.Cloud.Code
|
||||
{
|
||||
public class TreeViewModel
|
||||
{
|
||||
public string parentId { get; set; }
|
||||
public string id { get; set; }
|
||||
public string text { get; set; }
|
||||
public string value { get; set; }
|
||||
public int? checkstate { get; set; }
|
||||
public bool showcheck { get; set; }
|
||||
public bool complete { get; set; }
|
||||
public bool isexpand { get; set; }
|
||||
public bool hasChildren { get; set; }
|
||||
public string img { get; set; }
|
||||
public string title { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user