詳解Jquery EasyUI tree 的異步加載(遍歷指定文件夾,根據(jù)文件夾內(nèi)的文件生成tree)
更新時間:2017年02月11日 16:37:54 作者:水墨晨詩
本篇文章主要介紹了Jquery EasyUI tree 的異步加載,可以實現(xiàn)遍歷指定文件夾,根據(jù)文件夾內(nèi)的文件生成tree,有興趣的可以了解一下。
Jquery EasyUI tree 的異步加載(遍歷指定文件夾,根據(jù)文件夾內(nèi)的文件生成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>
/// 范圍指定目錄下的 文件夾/文件 數(shù)量
/// </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();//獲取文件夾數(shù)量
foreach (DirectoryInfo d in allDir)
{
allFileList.Add("0|" + d.Name);
}
FileInfo[] allFile = SMT_SOP.GetFiles();//獲取文件數(shù)量
foreach (FileInfo fi in allFile)
{
allFileList.Add("1|" + fi.Name);
}
return allFileList;
}
/// <summary>
/// 遍歷指定文件夾,根據(jù)文件夾內(nèi)的文件返回JSON
/// </summary>
/// <param name="filesNameList"></param>
/// <param name="id">第一次調(diào)用這個方法的時候,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中的模態(tài)窗口
var treeData = eval(result);
$("#tt").tree({
data: treeData})
}
})
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jQuery select自動選中功能實現(xiàn)方法分析
這篇文章主要介紹了jQuery select自動選中功能,結(jié)合實例形式分析了jQuery實現(xiàn)select響應(yīng)與級聯(lián)菜單顯示相關(guān)功能與操作技巧,需要的朋友可以參考下2016-11-11
jQuery頭像裁剪工具jcrop用法實例(附演示與demo源碼下載)
這篇文章主要介紹了jQuery頭像裁剪工具jcrop用法,結(jié)合實例形式分析了jQuery頭像裁剪工具jquery.jcrop.js具體使用技巧,并附帶了完整的demo源碼供讀者下載參考,需要的朋友可以參考下2016-01-01
jQuery oLoader實現(xiàn)的加載圖片和頁面效果
我們使用jQuery的ajax在頁面中就像使用iframe一樣加載其他頁面內(nèi)容,今天我給大家分享一個名叫jQuery oLoader的插件,該插件還集成了oPageLoader,可以輕松實現(xiàn)加載圖片和頁面的漂亮效果。2015-03-03
使用jQuery.form.js/springmvc框架實現(xiàn)文件上傳功能
這篇文章主要介紹了使用jQuery.form.js/springmvc框架實現(xiàn)文件上傳功能,非常具有參考借鑒價值,感興趣的朋友一起學(xué)習(xí)吧2016-05-05

