这篇文章主要介绍了Jquery EasyUI tree异步加载的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
具体代码如下:
private void SMT(HttpContext context)
{
string SqlConnection82 = System.Configuration.ConfigurationManager.AppSettings["LocalConnectionString"];
string path = context.Server.MapPath(@"~/CISWeb/SMT_SOP");
string id = string.Empty;
List<string> filesNameList = getFiles(path);
if (filesNameList.Count > 0)
context.Response.Write(ListToJson(filesNameList,id));
else
{
context.Response.Write("0");
}
}
/// <summary>
/// 范围指定目录下的 文件夹/文件 数量
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
private static List<string> getFiles(string path)
{
DirectoryInfo SMT_SOP = new DirectoryInfo(path);
List<string> allFileList = new List<string>();
DirectoryInfo[] allDir = SMT_SOP.GetDirectories();//获取文件夹数量
foreach (DirectoryInfo d in allDir)
{
allFileList.Add("0|" + d.Name);
}
FileInfo[] allFile = SMT_SOP.GetFiles();//获取文件数量
foreach (FileInfo fi in allFile)
{
allFileList.Add("1|" + fi.Name);
}
return allFileList;
}
/// <summary>
/// 遍历指定文件夹,根据文件夹内的文件返回JSON
/// </summary>
/// <param name="filesNameList"></param>
/// <param name="id">第一次调用这个方法的时候,id=""</param>
/// <returns></returns>
public string ListToJson(List<string> filesNameList,string id)
{
StringBuilder sb2 = new StringBuilder();
sb2.Append("[");
for (int i = 0; i < filesNameList.Count; i++)
{
if (filesNameList[i].ToString().Split('|')[0] == "0")
{
sb2.Append("{ \"id\":" +id+ (i + 1).ToString() + ",\"text\":\"" + filesNameList[i].ToString().Split('|')[1] + "\",\"state\":\"closed\",\"children\": [");
sb2.Append("]},");
}
else
{
sb2.Append("{\"id\":"+id + (i + 1).ToString() + ",\"text\":\"" + String.Format(filesNameList[i].ToString().Split('|')[1]) + "\"},");
}
}
sb2.Remove(sb2.Length - 1, 1);
sb2.Append("]");
return sb2.ToString();
}
前台
$.ajax({
type: "post",
url: "../../ajax/Handler.ashx?action=SMT",
data: {},
success: function (result) {
$("#menuDiv").dialog("open");//jQuery UI中的模态窗口
var treeData = eval(result);
$("#tt").tree({
data: treeData})
}
})
感谢你能够认真阅读完这篇文章,希望小编分享的“Jquery EasyUI tree异步加载的示例分析”这篇文章对大家有帮助,同时也希望大家多多支持编程网,关注编程网行业资讯频道,更多相关知识等着你来学习!