提交rbac
提交设置右键错位的bug
This commit is contained in:
55
DH.RBAC/Utility/Other/TreeSelect.cs
Normal file
55
DH.RBAC/Utility/Other/TreeSelect.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace DH.RBAC.Utility.Other
|
||||
{
|
||||
/// <summary>
|
||||
/// Select2树形下拉列表模型。
|
||||
/// </summary>
|
||||
public class TreeSelect
|
||||
{
|
||||
public string id { get; set; }
|
||||
public string text { get; set; }
|
||||
public string parentId { get; set; }
|
||||
public object data { get; set; }
|
||||
}
|
||||
|
||||
public static class TreeSelectHelper
|
||||
{
|
||||
public static string ToTreeSelectJson(this List<TreeSelect> data)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("[");
|
||||
sb.Append(ToTreeSelectJson(data, "0", ""));
|
||||
sb.Append("]");
|
||||
return sb.ToString();
|
||||
}
|
||||
private static string ToTreeSelectJson(List<TreeSelect> data, string parentId, string blank)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var childList = data.FindAll(t => t.parentId == parentId);
|
||||
|
||||
var tabline = "";
|
||||
if (parentId != "0")
|
||||
{
|
||||
tabline = " ";
|
||||
}
|
||||
if (childList.Count > 0)
|
||||
{
|
||||
tabline = tabline + blank;
|
||||
}
|
||||
foreach (TreeSelect entity in childList)
|
||||
{
|
||||
entity.text = tabline + entity.text;
|
||||
string strJson = JsonConvert.SerializeObject(entity);
|
||||
sb.Append(strJson);
|
||||
sb.Append(ToTreeSelectJson(data, entity.id, tabline));
|
||||
}
|
||||
return sb.ToString().Replace("}{", "},{");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user